<pre name="code" class="plain">#include <stdio.h>
int main () {
//交换a和b的值
int a = 10;
int b = 11;
//通过第三个值
int c = a;
a = b;
b = c;
printf("a=%d,b=%d\n",a,b);
//通过加减法
a = b-a;
b = b-a;
a = a+b;
printf("a=%d,b=%d\n",a,b);
//通过位运算(异或)
a = a^b;
b = a^b;
a = a^b;
printf("a=%d,b=%d\n",a,b);
int d = 12;
//使用位与运算判断奇数偶数
d&1?printf("奇数\n"):printf("偶数\n");
return 0;
}
C 交换两个整形变量的值
最新推荐文章于 2021-05-18 11:32:03 发布