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)+
- The three XORs swap the two values.
- Whatever was in j ends up in i.
Answer
Reveal answer →Final 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.