What is function prototype?

C Programming Language >   Function in C Language >   Function Calling in C  

Long Question

900


Answer:

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.

Code:

#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;
}

Output:

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 */


This Particular section is dedicated to Question & Answer only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.