Function Prototypes
A function prototype is a declaration that indicates the types of the function’s parameters as well as its return value. For example:
double pow( double, double ); // prototype of pow()
This prototype informs the compiler that the function
pow() expects two arguments of type
double, and returns a result of type
double. Each parameter type may be followed by a
parameter name. This name has no more significance than a comment,
however, since its scope is limited to the function prototype itself.
For example:
double pow( double base, double exponent );
Functions that do not return any result are declared with the
type specifier void.
For example:
void func1( char *str ); // func1 expects one string
// argument and has no return
// value.Functions with no parameters are declared with the type specifier
void in the parameter list:
int func2( void ); // func2 takes no arguments and
// returns a value with type int.Function declarations should always be in prototype form. All
standard C functions are declared in one (or more) of the standard
header files. For example, math.h contains the
prototypes of the mathematical functions, such as
sin(), cos(),
pow(), etc., while stdio.h
contains the prototypes of the standard input and output functions.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access