Home Segments Index Top Previous Next

244: Mainline

The solution to the rabbits dilemma is to use a function prototype. A function prototype is like a function definition without parameter names or a body. By supplying a function prototype, you supply only what the C compiler needs to know about a function's parameter types and return type in order to prepare calls to the function. In the function prototype of rabbits, for example, the parameter name and the entire body disappear, leaving only the data-type declarations for the return value and the parameter:

int rabbits (int); 

Because the body of the function is supplied later, a function prototype cannot refer to other functions, be they defined or not yet defined. Other definitions can refer to the function once its function prototype has been seen, however.