Questions: Call Stack and Function Call Execution

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A programmer defines `count = 0` inside function `increment()` and increments it before returning. Every call to `increment()` starts with `count = 0` instead of preserving the previous value. What explains this?

APython automatically resets integer variables to 0 between function calls as a safety measure
BEach call to `increment()` creates a new stack frame with its own fresh `count`, independent of all previous calls
CThe variable is stored on the heap and garbage-collected after each call returns
DLocal variables are shared across all calls to the same function, so `count` should persist — this must be a bug elsewhere
Question 2 Multiple Choice

During execution, the call sequence is: main() → process() → validate(). Where is the stack frame for process() while validate() is executing?

AAll three frames are on the stack simultaneously: validate() on top, process() in the middle, main() at the bottom
BOnly validate()'s frame is on the stack — process()'s frame was removed when it called validate()
Cprocess() and main() have been removed from the stack since they called other functions before completing
DThe frames are stored in a queue ordered by call time, not a stack
Question 3 True / False

When function A calls function B, function A's stack frame is temporarily removed from the call stack while B executes, then restored when B returns.

TTrue
FFalse
Question 4 True / False

Each invocation of a function gets its own independent stack frame, even when the same function is called multiple times — including recursively.

TTrue
FFalse
Question 5 Short Answer

How does the call stack explain why two separate calls to the same function each get their own independent copies of local variables?

Think about your answer, then reveal below.