对两个变量的值进行互换
方法一:
int x=3,y=6;
int z;
z = x;
x = y;
y = z;
方式二:
x = x+y;//x = 3+6; x = 9;
y = x-y;//y = 9-6; y = 3;
x = x-y;//x = 9-3; x = 6;
方式三:
x = x^y;//x = 3^6;
y = x^y;//y = (3^6)^6;y = 3;
x = x^y;//x = (3^6)^3;x = 6;
方法一:
int x=3,y=6;
int z;
z = x;
x = y;
y = z;
方式二:
x = x+y;//x = 3+6; x = 9;
y = x-y;//y = 9-6; y = 3;
x = x-y;//x = 9-3; x = 6;
方式三:
x = x^y;//x = 3^6;
y = x^y;//y = (3^6)^6;y = 3;
x = x^y;//x = (3^6)^3;x = 6;