The function declaration or
prototype is model or blueprint of the function. If functions are used before
they are defined, then function declaration or prototype is necessary. Many programmers
prefer a “top-down” approach in which main appears ahead of the programmer defined
function definition. Function prototypes are usually written at the beginning
of a program, ahead of any user-defined function including main(). Function
prototypes provide the following information to the compiler.
− The name of the function
− The type of the value returned by the function
− The number and the type of arguments that must be supplied
while calling the function.
In “bottom-up” approach where user-defined functions
are defined ahead of main() function, there is no need of function prototypes.
The general syntax of function prototype is
return_type
function_name (type1, type2, ...., typen) ;
where, return_type specifies the data type of the
value returned by the function. A function can return value of any data type.
If there is no return value, the keyword void is used. type1, type2, .....,
typen are type of arguments. Arguments are optional.
For example:
int add (int,
int) ; /* int add (int a, int b) ;
void display
(int a) ; /* void display (int); */
Comments
Post a Comment