ITPEC FE Subject B April 2026 Question 5

Topic: Stack

From the answer group below, select the correct answer to be inserted into blank in the description.

When the procedure proc1 is called, the output is “blank” in turn.

[Program]
○ proc1()
proc2()
proc3()
output "A, "
○ proc2()
output "B, "
proc3()
○ proc3()
output "C, "

Answer group

Explanation

B, C, C, A — a call runs to completion before the statement after it starts, so proc1 prints its own A last.

  • •proc1 first calls proc2
  • •proc2 outputs B, then calls proc3, which outputs C
  • •control returns to proc1, which calls proc3 directly: another C
  • •only then does proc1 reach its own output statement: A

proc3 runs twice, once from inside proc2 and once from proc1.

Answer (e)

Why not others:

  • •(a) and (b) — put A first, but proc1 outputs only after both of its calls have returned
  • •(c) — puts A second, as if proc1 printed between its two calls
  • •(d) — prints B again in third place, but the second call in proc1 is proc3, which prints C; nothing calls proc2 twice
  • •(f), (g) and (h) — start with C, but proc2 outputs B before it calls proc3

Key rule: Read a call as "pause here, run the whole procedure, come back"; the order of statements inside each procedure decides whether its own output comes before or after the calls it makes.

Stack · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.