ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
a, b = 5, 9
a ^= b
b ^= a
a ^= b
print(a, b, a ^ b)
  1. A. 5 9 12
  2. B. 9 5 0
  3. C. 9 5 12
  4. D. 9 5 14

Correct answer: C. 9 5 12

Three XORs swap two values without a temporary variable. After the swap the XOR of the two numbers is unchanged, and 5 ^ 9 is 12.

More Python Programming questions

Exams that ask this topic