DEV Community

Discussion on: How can you swap two variables without using a third?

Collapse
 
johnfound profile image
johnfound • Edited

No, it will not. Let set x=5, y=5.

x = x xor y = 5 xor 5 = 0
y = y xor x = 5 xor 0 = 5
x = x xor y = 0 xor 5 = 5

It is a nop actually, but still correct.