一、分析
使用位运算交换整数,可使用按位异或的方法,省掉临时变量,减少空间复杂度
二、源码
1: #include "stdio.h"
2:
3: int main()
4: {
5: int a, b;
6: a = 5;
7: b = 10;
8: printf("a = %d, b = %d\n", a, b);
9: a = a ^ b;
10: b = b ^ a;
11: a = a ^ b;
12: printf("a = %d, b = %d\n", a, b);
13: getchar();
14: return 0;
15: }