< previous page page_335 next page >

Page 335
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Function Call (To a Void Function) A statement that transfers control to a void function. In C++, this statement is the name of the function, followed by a list of actual parameters.
According to the syntax template for a function call, the parameter list is optional. A function is not required to have parameters. However, as the syntax template also shows, the parentheses are required even if the parameter list is empty.
If there are two or more parameters in the parameter list, you must separate them with commas. Here is the syntax template for ActualParameterList:
0335-01.gif
When a function call is executed, the actual parameters are passed to the formal parameters according to their positions, left to right, and then control transfers to the first executable statement in the function body. When the last statement in the function has executed, control returns to the point from which the function was called.
Function Declarations and Definitions
In C++, you must declare every identifier before it can be used. In the case of functions, a function's declaration must physically precede any function call.
A function declaration announces to the compiler the name of the function, the data type of the function's return value (either void or a data type like int or float), and the data types of the parameters it uses. The NewWelcome program shows a total of three function declarations. The first declaration (the statement labeled Function prototype) does not include the body of the function. The remaining two declarationsfor main and PrintLinesinclude bodies for the functions.
In C++ terminology, a function declaration that omits the body is called a function prototype, and a declaration that does include the body is a function definition. We can use a Venn diagram to picture the fact that all definitions are declarations, but not all declarations are definitions:

 
< previous page page_335 next page >