Multiple choice technology programming languages

What will be the output of the following code: main() { int a=10,b=20; a=a^b; b=a^b; a=a^b; cout<

  1. 20,10

  2. 10,20

  3. 1,10

  4. 20,2

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

This code uses XOR swap algorithm. a=10, b=20. After a=a^b: a=30, b=20. After b=a^b: a=30, b=10. After a=a^b: a=20, b=10. The XOR operation reverses the swap in the last step, effectively exchanging the values. This is a classic technique for swapping without a temporary variable.