Questions: Activation Records and Stack Frames

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

What enables a recursive function to have independent copies of its local variables for each level of nesting, even though all levels execute the same code?

AThe compiler generates a separate copy of the function code for each recursive invocation
BEach function call creates a new activation record on the call stack, giving each invocation its own independent storage for locals and parameters
CLocal variables are stored in a global hash table indexed by call depth
DRegisters are multiplied — the CPU allocates a fresh register file per call
Question 2 Multiple Choice

A function allocates a local character array `char buf[8]` and an attacker writes 20 bytes into it via an unchecked input. What does activation record layout explain about the consequence?

ANothing; the operating system prevents writes beyond the declared array size
BThe extra bytes overwrite adjacent regions of the activation record — potentially including the saved return address — redirecting control flow when the function returns
CThe local array silently expands to accommodate the overflow
DThe extra bytes overwrite heap memory, not stack memory
Question 3 True / False

Each function call pushes a new activation record onto the call stack, which is why recursive functions correctly maintain independent copies of local variables at every nesting level.

TTrue
FFalse
Question 4 True / False

Returning a pointer to a local variable is safe as long as the caller dereferences it before calling any other function, since the stack has not yet been reused.

TTrue
FFalse
Question 5 Short Answer

Explain why tail-call optimization allows a recursive function to run in constant stack space, using the concept of activation records.

Think about your answer, then reveal below.