标签:
int a = 10;
int b = 20;
第一种方法:
a = a + b;
b = a - b;
a = a - b;
第二种方法:
a = a ^ b; (^ 语言中是异或的意思,同为0 异为1 1 ^ 1 = 0, 0 ^ 0 = 0, 1 ^ 0 = 1)
b = a ^ b;
a = a ^ b;
第三种方法 (这种方法容易越界)如果a 大于int型最大值了!
a = (a + b) - (b = a);
标签:
原文地址:http://www.cnblogs.com/wangqi1221/p/5240252.html