Section 7.3. How Functions Are Executed


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).



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net