ITPEC FE Subject B April 2026 Question 1
From the answer group below, select the correct answer to be inserted into blank in the description. Here, the array index starts at 1.
When the program is executed, the output is “blank”.
Answer group
Explanation
1, 2 — trace the assignments in order; each one copies the value its right-hand side holds at that moment.
Starting state: x = 1, y = 2, z = 3, ar = {0, 0}.
- •
y ← x—ybecomes 1, and the initial 2 is gone from here on - •
ar[x] ← y—xis 1, soar[1]becomes 1 and the array is {1, 0} - •
z ← y—zbecomes 1 - •
x ← z—xstays 1 - •
ar[2] ← z + ar[1]— 1 + 1 = 2, so the array is {1, 2}
The output is 1, 2.
Answer (c)
Why not others:
- •(a) 1, 0 — leaves
ar[2]at its initial 0, skipping the last assignment - •(b) 1, 1 — adds the initial
ar[1]of 0 toz, missing thatar[1]was set to 1 two lines earlier - •(d) 2, 1, (e) 2, 2 and (f) 2, 3 — start with
ar[1]= 2, which keeps the originaly= 2 and ignores the first assignmenty ← x
Key rule: Keep a table of the variables and update it line by line; an assignment copies a value once and does not link the two variables afterwards.
Array Manipulation · 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.