logo

Question detail

Describe what happens to stack frames when subroutine A calls subroutine B, and subroutine B then calls subroutine C. Explain the order in which the frames are used and removed, and why each frame must retain its own information.

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

Question

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

Describe what happens to stack frames when subroutine A calls subroutine B, and subroutine B then calls subroutine C. Explain the order in which the frames are used and removed, and why each frame must retain its own information.

Model answer

What a good answer should say

  • A stack frame for subroutine A is active first.
  • When A calls B, a new frame for B is placed on top of A's frame.
  • The B frame contains B's return address, parameters and local variables.
  • If B calls C, a new C frame is placed on top of B's frame and contains C's corresponding information.

Explanation

Why this works

The essential sequence is last in, first out: C's frame is removed first, then B's, while A's remains below them. The explanation must also connect separate frames with the preservation of return addresses, parameters and local variables.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.