I don't know if anybody comes back to these pages, but no, the original value of a is not lost in a = a ^ b as long as you know b. So then b = b ^ a in terms of the original values is b = b ^ (a ^ b) = a. Then the final a = a ^ b in terms of the original values is a = (a ^ b) ^ a = b. Three function points, I agree, but only one statement. And don't expect any promotion to occur if the variables are different types!
Register swapping is what I was thinking of when I suggested assembly language. After all, the question didn't say arbitrary variables... |