< previous page page_102 next page >

Page 102
0102-01.gif
The parameter list is a way for functions to communicate with each other. Some functions, like Square and Cube, have a single parameter in the parameter list. Other functions, like main, have no parameters in the list. And some functions have two, three, or more parameters in the parameter list, separated by commas.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Parameter List A mechanism by which functions communicate with each other.
Value-returning functions are used in expressions in much the same way that variables and constants are. The value computed by a function simply takes its place in the expression. For example, the statement
someInt = Cube(2) * 10;
stores the value 80 into someInt. First the Cube function is executed to compute the cube of 2, which is 8. The value 8-now available for use in the rest of the expression-is multiplied by 10. Note that a function call has higher precedence than multiplication, which makes sense if you consider that the function result must be available before the multiplication takes place.
Here are several facts about value-returning functions:
ò The function call is used within an expression; it does not appear as a separate statement.
ò The function computes a value (result) that is then available for use in the expression.
ò The function returns exactly one result-no more, no less.
The Cube function expects to be given (or passed) a parameter of type int. What happens if the caller passes a float parameter? The answer is that the compiler applies implicit type coercion. The function call Cube (6.9) computes the cube of 6, not 6.9.
Although we have been using literal constants as parameters to Cube, the parameter could just as easily be a variable or named constant. In fact, the parameter to a value-returning function can be any expression of the appropriate type. In the statement

 
< previous page page_102 next page >