ITPEC IP October 2021 Question 8

Source exam: ITPEC IP October 2021Topic: Algorithm and Programming

ITPEC IP October 2021 — Question 8 of 100

The correct swap is TMP ← A, A ← B, then B ← TMP. The first assignment preserves A's original value before A is overwritten. The second copies B's original value into A, and the third restores the saved original A value into B.

Answer (b)

Why not others:
- assigning B from A after A has already been overwritten makes both variables equal to the original B

- saving B but then overwriting A from B requires the final assignment to restore TMP into B differently

Key rule: Preserve one original value in a temporary variable before overwriting either side of a swap.

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.