不创建临时变量,来交换两个变量的值

不创建临时变量交换两个数的内容
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 3;
int b = 4;
a = a + b; //将a+b赋值给a(a=3+4=7)
b = a - b; //将a-b赋值给b(b =7-4=3 )
a = a - b; (a =7-3=4 )
printf("%d,%d\n", a, b);
system(“pause”);
return 0;
}

运行结果:4
3

猜你喜欢

转载自blog.csdn.net/weixin_43224539/article/details/82832378
今日推荐