- #include <stdio.h>
- #include <stdlib.h>
- void swap(int * a, int * b);
- int main(int argc, char * argv[])
- {
- int a = 10;
- int b = 8;
- int x = 10;
- int y = 8;
- printf("before a = %d, b = %d\\n", a, b);
- swap(&a, &b);
- printf("after swap a = %d, b = %d\\n", a, b);
- printf("before x = %d, y = %d\\n", x, y);
- x = x + y;
- y = x - y;
- x = x - y;
- printf("after swap x = %d, y = %d\\n", x, y);
- system("pause");
- return EXIT_SUCCESS;
- }
- void swap(int * a, int * b)
- {
- *a ^= *b^= *a^= *b;
- }
- //该片段来自于http://www.codesnippet.cn/detail/141120137151.html
来源: http://www.codesnippet.cn/detail/141120137151.html