Order of execution
When a program executes, it finds main()
and begins executing statements in the main()
function block. Whenever a function call statement is encountered, several actions occur:
- If there are function parameters, the actual values that are found in the function call statement are assigned to the function parameter names.
- Program execution jumps to that function and begins executing statements in that function block.
- Execution continues until either a return statement is encountered or the end of the block is encountered (the closing
}
). - Execution jumps back, or returns, to the calling function and resumes from that point.
If, in Step 2, execution encounters another function call statement, the steps are repeated from Step 1.
The following diagram illustrates the call/return order of execution when function calls are encountered. Notice that in every case, the called function returns to the location of...