In the portion of program, where user defines variable, functions can be declared or defined using following syntax :
data-type name of function (datatype 1 arg1, datatype 2 arg 2,datatype n arg n);
where arg 1, arg 2, .......arg n are arguments of this function and datatype 1 datatype are data types of these individual arguments. Function declaration written in its fashion are called function prototype.
Ex.
int fort (int n);
int ncr (int n, int r);
float ncr (int n, int r);
The data type written before name of the function is the type of result the function returns. The use of function prototype is not mandatory in C. Function prototype are desirable, because they further facilitate error checking between the call to a function and the corresponding function definition.
When the function is called, the name of the actual arguments need not be the same as the names shown in the declaration. However, the data types of the actual arguments must conform to the data types of the arguments within the declaration.
data-type name of function (datatype 1 arg1, datatype 2 arg 2,datatype n arg n);
where arg 1, arg 2, .......arg n are arguments of this function and datatype 1 datatype are data types of these individual arguments. Function declaration written in its fashion are called function prototype.
Ex.
int fort (int n);
int ncr (int n, int r);
float ncr (int n, int r);
The data type written before name of the function is the type of result the function returns. The use of function prototype is not mandatory in C. Function prototype are desirable, because they further facilitate error checking between the call to a function and the corresponding function definition.
When the function is called, the name of the actual arguments need not be the same as the names shown in the declaration. However, the data types of the actual arguments must conform to the data types of the arguments within the declaration.
No comments:
Post a Comment