#include<stdio.h>
#include<stdlib.h>
main()
{
int x = 1;
int y= 2000;
int temp = 0;
temp = y;
y = x;
x = temp;
printf("x=%d,y=%d\n", x,y);
system("pause");
return 0;
}
如果不创建临时变量,程序可以这样写:
#include<stdio.h>
#include<stdlib.h>
main()
{
int x = 1;
int y= 2000;
int temp = x+y;
y = temp-y;
x = temp-y;
printf("x=%d,y=%d\n", x,y);
system("pause");
return 0;
}