What happens to control flow when a return statement is executed inside a…
2026
What happens to control flow when a return statement is executed inside a function?
Answer: B. The function exits immediately, and control returns to the caller at the statement immediately after the function call. — ConceptA function call transfers control from a caller to a function and records a return point in the caller. That return point is the statement immediately…
- A.
The program pauses and waits for user input.
- B.
The function exits immediately, and control returns to the caller at the statement immediately after the function call.
- C.
The function restarts from the beginning in a continuous loop.
- D.
The entire program terminates and closes.
Attempted by 747 students.
Show answer & explanation
Correct answer: B
Concept
A function call transfers control from a caller to a function and records a return point in the caller. That return point is the statement immediately after the call.
A return statement ends the current function invocation. It may also provide a value to the caller, but its control-flow effect is to resume execution at the recorded return point.
Application
The caller invokes the function, so control enters the function and the next caller statement is saved as the return point.
Statements in the function execute in sequence until the return statement is reached.
Executing return ends that invocation immediately; statements later in the function body are skipped.
Control resumes in the caller at the statement immediately after the function call.
Cross-check and contrast
Pausing for user input requires an input operation; return does not create an input-wait state.
Restarting from the beginning requires a loop, recursion, or another call; return does not create repetition.
Terminating the whole program ends the process; returning from an ordinary function only ends that function invocation.
Therefore, the function exits immediately and control returns to the caller at the statement immediately after the function call.