C Programming Tutorial
Computer Tutorial

Function Prototypes Declaration



Function Prototypes Declaration

In modern, properly written C programs, all functions must be declared before they are used. This is normally accomplished using a function prototype. Prototypes enable the compiler to provide stronger type checking.
When you use prototypes, the compiler can find and report any questionable type conversions between the arguments used to call a function and the type of its parameters. The compiler will also catch differences between the number of arguments used to call a function and the number of parameters in the function.
The general form of a function prototype is :
type func_name(type parm_namel, type parm_name2, . . . , type parm_nameN);

The use of parameter names is optional. However, they enable the compiler to identify any type mismatches by name when an error occurs, so it is a good idea to include them.

Function Prototypes Declaration

If a function is to accept arguments, it must declare the parameters that will receive the values of the arguments. As shown in the following function, the parameter declarations occur after the function name.

A Program to find sum of three number usning Function

\* C Program to find sum of three number usning Function *\
# include < stdio.h >
int  calsum (  int x, int y, int z) ;
int   main( )
{

int   a, b, c  ;
printf("\n Enter any three numbers : " ) ;
scanf(" %d %d %d " ,  &a, &b, &c ) ;
sum = calsum ( a, b, c ) ;
printf(" \n Sum = %d " ,  sum ) ;
return ( 0 ) ;

}
int  calsum (  x, y, z
{

int   x, y, z, d  ;
d = x + y + z   ;
return ( d ) ;

}

Output :

Enter any three numbers : 10 20 30
Sum = 60
Even though parameters perform the special task of receiving the value of the arguments passed to the function, they behave like any other local variable.