When using compound assignment operators, e.g x += y; which is equal to x = x + y; the lvalue (x) is evaluated only once. It means that x is saved before calculating the sum x + y.
So in our case the left most a[0] value is evaluated before the right part is. a[0] = 2, a[1] = 3 and a[0] ^= (a[1] ^= a[0] ^= a[1]); is equal to a[0] = a[0] ^ (a[1] ^= a[0] ^= a[1]); and it's equal to a[0] = 2 ^ (a[1] ^= a[0] ^= a[1]); Therefore after executing the part in brackets (a[1] ^= a[0] ^= a[1]) a[1] will be equal to a[0] (2) and a[0] ^ a[0] (or 2 ^ 2) gives us a zero.
Comments
Leave a comment