Exam-style question
Try this first
A subroutine calls itself recursively. Why can separate stack frames be needed for the different calls?.
- A.Each call has its own return address, parameters and local variables
- B.Only the first call needs a stack frame; later calls share all its data
- C.Recursive calls do not use stack frames
- D.A new frame is created only when a parameter has no value
Model answer
What a good answer should say
- Each call has its own return address, parameters and local variables
Explanation
Why this works
Each recursive call is a separate active subroutine call. Its stack frame preserves its own data and return location, so the calls can later return in the correct order.
Common mistake
No common mistake is linked to this question yet.
