Multiple choice

The minimum number of temporary variables needed to swap the contents of two variables, is

  1. 1

  2. 2

  3. 3

  4. 0

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To swap two variables (a and b), you typically use one temporary variable (temp = a; a = b; b = temp;). While XOR swapping can be done with zero extra variables, the standard algorithmic approach taught in introductory programming uses one.