+92 332 4229 857 99ProjectIdeas@Gmail.com

Function prototype (C++)


Function prototype
Function prototype also termed as function declaration comprises of following:
1.  Name of the function
2.  Return type of the function
3.  Arity of a function (Number of parameters)
4.  The data types of the parameters
5.  The order of the parameters in which they appear

For example
Let’s take an example of add function:
double add(int x, double y)
{
       return x+y;
}


The prototype of the above mentioned function is:
double add( int , double );

Prototype of add function comprises of:
1.  Name of the function : add
2.  Return type of the function : double
3.  Arity of a function (Number of parameters) : 2
4.  The data types of the parameters : int , double
5.  The order of the parameters in which they appear : first is int and the second is double

Need of function prototype
If the function is invoked before it is defined then function prototype is needed, but if the function is defined before it is invoked then there is no need of function prototype, function definition serves the purpose.


Related articles

0 comments: