变量之间交换数据(不用第三变量)

编程之中却有诸多美妙之处。

#include <STDIO.H>

int main()
{

 int a,b;
 printf("input the value of a and b:\n");
 scanf("%d%d",&a,&b);

 printf("before exchange:");
 printf("a=%d\tb=%d\n",a,b);

 a=a+b;
 b=a-b;
 a=a-b;

 printf("after the 1st:");
 printf("a=%d\tb=%d\n",a,b);

 a=a^b;
 b=b^a;
 a=a^b;

 printf("after the 2nd:");
 printf("a=%d\tb=%d\n",a,b);

 return 0;
}

原文地址:https://www.cnblogs.com/xingma0910/p/2607254.html