Function Prototype
Function Prototypes are usually written at the beginning of a program, ahead of any programmer-defined function (including main). The general form of a function prototype is
data_type name (type1 arg1, type2 arg2,..............,type n argn);
Where data_type represents the data type of the item that is returned by the function, name represents the function name, and type1, type2,......,type n represents the data types of the arguments arg1,arg2,........,arg n. Notice that a function prototype resembles the first line of a function definition (though a function prototype ends with a semicolon). For Example- The statements given below are examples of function prototypes.
(a) float sum(float, int);
(b) float sum(float x, int y);
In the statement (a) the prototype of function sum() is declared. Its return value is float and arguments are float and integer type respectively. It tells the compiler the return value of the function is float and type of arguments used by this function.
In the example (b) with argument type, argument names are also declared. It is optional and also not compulsory to use the same variable name in the program. For Example:
#include<stdio.h>
long int factorial (int); //function prototype
main( )
{
int n;
/* read in the integer quantity*/
printf("\n Enter any value for n=");
scanf("%d",&n);
/* calculate and display the factorial*/
printf("\n n!=%ld",factorial(n) );
}
long int factorial (int n)
/* calculate the factorial of n */
{
int i;
long int prod=1;
if (n>1)
for (i=2;i<=n;++i)
prod*=i;
return(prod);
}