使用"异或"运算而不需要临时变量交换两个变量的值

#include<stdio.h>
int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    a^=b^=a^=b;
    printf("a = %d b = %d\n", a, b);
    return 0;
}

变量类型是整型或字符型才可以使用该方法。

猜你喜欢

转载自blog.csdn.net/qq_41895253/article/details/82345729