^是位异或逻辑预算。
比如a = 1, b = 2;
a = a^b; → a =1^2; → a =0001^0010(这里把十进制的1和2换成二进制);→ a = 0011(0001和0010对应位相同时为假(即0),不同时为真(即1)) = (此时换算成十进制)3 ;
根据以上方法:
b = a^b; → b = 3^2; → b = 0011^0010 = 0001=1;
a = a^b; → a = 3^1; → a = 0011^0001 = 0010 =2;
现在就是a = 2,b = 1;了