Swap without a temp

Two integers are swapped without a temporary using i ^= j; j ^= i; i ^= j;. If i = 5 and j = 9 before, what is i afterwards?

Show hints (2)+
  1. The three XORs swap the two values.
  2. Whatever was in j ends up in i.

Answer

Reveal answer →

9

Want the full step-by-step worked solution? It's part of Premium — along with a worked solution for every question in the bank.

Asked at: DRW, Two Sigma

Related questions