IPA FE Subject B 2023 Question 2
A question IPA Japan published in 令和5年度 基本情報技術者試験 科目B 公開問題 問2, translated into English. ITPEC is based on the same exams.
From the answer group below, select the correct answer to be inserted into blank in the description.
In the following program, when the procedure proc2 is called, blank are output in this order.
Answer group
Explanation
“C”, “B”, “A”, “C” — a called procedure runs to its end before the caller goes on to its next statement.
Tracing the call of proc2:
proc2first callsproc3, which outputs C- back in
proc2, it outputs B proc2then callsproc1, which outputs Aproc1then callsproc3, which outputs C again
proc3 runs twice, once from proc2 and once from proc1, so four values are output in all.
Answer (h)
Why not others:
- •(a), (b) and (c) — start with A, but
proc1, the only procedure that outputs A, is called last byproc2 - •(d) and (e) — start with B, but
proc2outputs B only after its first statement, the call ofproc3, has output C - •(f) and (g) — stop early, leaving out the output of
proc1or of theproc3it calls at its end
Key rule: Read each call as "pause here, run the whole procedure, come back", and follow the statements in order inside every procedure, including the calls a called procedure makes.
Stack · AI-written, may contain errors
This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.