Every function in C
programming should be declared before they are used. This type of declaration
are also called function prototype. Function prototype gives compiler information
about function name, type of arguments to be passed and return type.
Syntax
of Function Prototype:
return_type
function_name(type(1) argument(1),….., type(n) argument(n));
Here, in the above example, function prototype
is “int add(int a, int b);” which provides following information to the
compiler:
1.
Name of the function is “add”
2.
Return type of the function is int.
3.
Two arguments of type int are passed to function.
Function prototype is not needed, if you write
function definition above the main function. In this program if the code from
line 12 to line 19 is written above main(), there is no need of function
prototype.
No comments:
Post a Comment