Function prototype or Function declaration
A function prototype is declaration of the function which tells the compiler about a function’s name, return type , number of parameter and types of parameters. It is used to say the compiler about existence of a function.
A function prototype is not required if a function defined before using it, Here the function definition will act as function prototype too. Next we will study about function definition.
Both C program given below will compile and give same output.
|
In below program, called function defined before using it.
|
Function definition
Actual body of function is called function definition. The general form of a function definition is given below.
return_type function_name (parameter1, parameter2 ……., parameter N) { /* function body */ }The smallest function is:- gt_function() { } This function is doing nothing and returns nothing. |
A function definition consists following things :-
Function Name – This is the actual name of the function.
Function Parameters – When a function is called, we pass a variable or value to the parameter. This is called actual parameter or argument. This is optional part in function.
Function Body – The function body contains a collection of statements inside function parenthesis.
Return Type – A function may return a value or may not. If the return type is not mentioned then int is assume. The return type of the function is the data type of the value the function returns. Some function doesn’t return anything. In this case the return type is keyword ‘ void ‘.