ITPEC IP April 2019 Question 5
ITPEC IP April 2019 — Question 5 of 100
The correct swap first preserves A in TMP, then copies B into A, and finally copies the saved value into B. The sequence is TMP ← A, A ← B, B ← TMP, so neither original value is lost before it reaches the other variable.
Answer (b)
Why not others:
- (a) overwrites A and then copies the new A into B, leaving both equal to original B
- (c) saves B but then restores B rather than preserving original A
- (d) overwrites A and never uses TMP to complete the exchange
Key rule: Before overwriting a value needed later, save it in temporary storage.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
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 IP past-paper collection or Report an issue.