Previous Page
Next Page

7.3. How Functions Are Executed

The instruction to execute a functionthe function callconsists of the function's name and the operator ( ) (see the section "Other Operators" in Chapter 5). For example, the following statement calls the function maximum( ) to compute the maximum of the matrix mat, which has r rows and c columns:

maximum( r, c, mat );

The program first allocates storage space for the parameters, then copies the argument values to the corresponding locations. Then the program jumps to the beginning of the function, and execution of the function begins with first variable definition or statement in the function block.

If the program reaches a return statement or the closing brace } of the function block, execution of the function ends, and the program jumps back to the calling function. If the program "falls off the end" of the function by reaching the closing brace, the value returned to the caller is undefined. For this reason, you must use a return statement to stop any function that does not have the type void. The value of the return expression is returned to the calling function (see the section "The return Statement" in Chapter 6).


Previous Page
Next Page