Function Declaration (Prototype):
The function declaration is also called prototype. Prototype means sample or model. The function declaration only provides the model of the function. Since function declaration provides the model of the function, it is called prototype.
In function declaration, the following information about the function is provided to the compiler:
• The name of function.
• The type of data returned by the function.
• The number and types of arguments or parameters used in the function.
Semicolon is used at the end of function declaration to indicate the end of function declaration.
The function declaration is similar to a variable declaration. The rules for naming functions are same as those fur naming variables.
Syntax of function declaration is:
type function-name (arguments);
type specifies the type of data returned by the function. For example, int is used it the function returns integer type data. Similarly, float is used if the function is to return floating-point data.
If the function does not return any value, the word void is used.
function-name specifies the name of the function.
arguments specifies the type of parameters separated by commas that are provided to the function.
Examples:
void display (void);
The above function declaration provides the following information about the function:
• name of the function is “display”.
• return data type is void, it does not return any value.
• list of parameters is void, no parameters or arguments are required.
The above declaration of the “sum” function provides the following information:
• name of the function is “sum”.
• return data type is integer.
• two parameters, both of integer type are required.
float temp (void);
The above declaration of the “temp” function provides the following information:
name of the function is “temp”.
• return data type is float.
• list of parameters is void (nothing).
void print (int, float, char);
The above declaration of the “print” function provides the following
information: -
• name of the function is “print”.
• return data type is void (nothing).
• three parameters, first integer type, second float type and third of character type are required.
The parameters of a function may be of int, float, double, char, string, array, pointer and structure type. Similarly, the returned value of the function may be of int, float, double or structure type.
comment closed