首页 > 代码库 > 数据互换

数据互换

1、定义中间变量

int a = 1,b = 2,t ;
t = a;
a = b;
b = t;

2、求和,可不用定义中间变量

int a = 1,b = 2;
a = a + b;
b = a - b;
a = a - b;

3、异或

int temp = p ^ q;
p = temp ^ p;
q = temp ^ q;

数据互换