✏️ Explanatory Question
The ANSI C standard introduces function prototypes. An example is given below. It also allows function definitions to be written in the same form as the new prototypes.
#include
double minimum(double, double);
/* prototype of minimum() */
int main()
{
printf("%f
", minimum(1.23, 4.56));
return 0;
}
double minimum(double x, double y)
/* definition of minimum() */
{
if (x < y)
return x;
else
return y;
}
1.230000
Press any key to continue . . .
The use of prototypes or the new style function definition allows the compiler to check that the parameters to a function are sensible (not necessarily the same), as well as checking the return type of the function; but only if the definition or prototype appears before the function call.
ANSI C draws a distinction between the following two statements. The first is a function declaration stating that fred takes an, as yet, unspecified number of parameters. The second is a function prototype which states that jim takes no parameters
double fred(); /* declaration */
double jim(void); /* prototype */