Function Definitions and Prototypes

Now that you understand some function basics, we can look at functions in more detail. A function, or more precisely, “function definition,” contains several parts. Figure 2.1 shows the parts of the sphere function definition from the VOLUME.C example in Chapter 1, “Anatomy of a C Program.”

The function “header” specifies the type of value a function returns and the function's name. The header also contains an argument list, which specifies the arguments the function requires. The rest of the function definition—everything inside the braces—is the function “body.”

The ANSI C standard, which QuickC follows, recommends that you supply a function “prototype” (declaration) for every function definition in your program. The prototype is identical to the function header except that it ends with a semicolon. Figure 2.2 shows the sphere function prototype from VOLUME.C.

The function prototype normally appears near the beginning of the program and serves a purpose similar to a variable declaration. It provides advance information about the function, which QuickC can use to check the accuracy of subsequent calls to the function. For more information, see “Function Prototypes,”.