实现两个整数变量交换的三种方式

第一种方式(推荐)

    int temp;
    temp = x;
    x = y;
    y = temp;

第二种方式:

有弊端,有可能会超出int的取值范围
    x = x + y;      
    y = x - y;          
    x = x - y;

第三种方式

 x=x^y;
 y=x^y;
 x=x^y;

猜你喜欢

转载自blog.csdn.net/weixin_42545256/article/details/82344190