Function Prototype/Function Declaration

The declaration of function in the program is known as Function Prototype.
The general syntax of function prototype is given below:
Return-type Function_ Name (Argument_List);

int sum (int a, int b);

Function Prototype provides following information to the compiler:
(1) Name of the Function
(2) Return Type of the Function
(3) Number of arguments and their Data Type
Whenever compiler founds any function call statement, first it will check function prototype to ensure following things:
(1) Weather the function that is called is declared or not.
(2) Weather proper number of arguments is passed while calling the function or not.
(3) Weather the data type of the arguments that are passed is corresponds to the arguments specified in the function prototype or not.
(4) If the function returns any value then it is corresponds to the return type specified in the function prototype or not.
If all the above mentioned criteria are satisfied then control of the program is transferred to the function definition otherwise compiler will generate error.

While declaring the function you should keep following points in the mind:
(1) You must specify data types for each argument separately.

int sum (int a, int b); // valid
int sum (int a, b); // Not Valid

(2) It is not compulsory to specify name of the arguments in the function declaration.

int sum (int, int); // valid

(3)If function does not accept any argument then you can leave the parenthesis empty.

int sum (); // valid

Download Projects

Download Programs