曾梦垚

导航

对两个变量的值进行互换

方法一:

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;

posted on 2016-11-16 20:31  曾梦垚  阅读(214)  评论(0编辑  收藏  举报