Here goes...
To make it easier to look at, stick some parens in there (though I believe it will produce a syntax error) [edit]VC++ doesn't seem to mind.[/edit]
x ^= (y ^= (x ^= y))
The innermost statement (x ^= y) will set x = 100(bin) = 4(dec)
Then, the middlemost(?) statement (y ^= (x ^= y)) sets y = (101 ^ 100) = 1
Finally, the outermost statement x ^= (y ^= (x ^= y)) sets x = (100 ^ 001) = 101(bin) = 5(dec)
In effect, it switches x and y. I could show the algebra that proves that this works for any x and y, but I'm lazy, so bleh.
__________________
When in doubt, sauerkraut.
|