Odd Issue with ^= operator in Java

Revision en1, by Tomg, 2021-03-27 04:47:47

In Java, why is it that the code a^=b^=a^=b does not swap the values of a and b, while in C++, such code works? For example if a=1, and b=5, in Java, after doing a^=b^=a^=b, a=0, b=1.

Tags #java, #xor

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Tomg 2021-03-27 04:47:47 218 Initial revision (published)