当我们想交换两个变量的值,一般来讲都是通过设置中间变量来完成的,这样会
消耗系统内存,增加不必要的冗余。以下程序通过异或来完美达到目的。
#include<stdio.h>
int main()
{
int a=1;
int b=2;
a=a^b;
b=a^b;
a=a^b;
printf("a=%d,b=%d\n",a,b);
return 0;
}
当我们想交换两个变量的值,一般来讲都是通过设置中间变量来完成的,这样会
消耗系统内存,增加不必要的冗余。以下程序通过异或来完美达到目的。
#include<stdio.h>
int main()
{
int a=1;
int b=2;
a=a^b;
b=a^b;
a=a^b;
printf("a=%d,b=%d\n",a,b);
return 0;
}