|
|
|
|
|
|
|
As you can see in the syntax template, no body is included for the function, and a semicolon terminates the declaration. The formal parameter list is optional and has the form |
|
|
|
|
|
|
|
|
The ampersand (&) attached to the name of a data type is optional and has a special significance that we cover later in the chapter. |
|
|
|
|
|
|
|
|
In a function prototype, the formal parameter list must specify the data types of the parameters, but their names are optional. You could write either |
|
|
|
|
|
|
|
|
void DoSomething( int, float ); |
|
|
|
|
|
|
|
|
void DoSomething( int velocity, float angle ); |
|
|
|
|
|
|
|
|
Sometimes it's useful for documentation purposes to supply names for the parameters, but the compiler ignores them. |
|
|
|
|
|
|
|
|
You learned in Chapter 2 that a function definition consists of two parts: the function heading and the function body, which is syntactically a block (compound statement). Here's the syntax template for a function definition, specifically for a void function: |
|
|
|
|
|