不通过中间变量交换两个变量的值

来源:互联网 发布:淘宝助理发布二手宝贝 编辑:程序博客网 时间:2024/06/07 01:12

在《STM32嵌入式微控制器快速上手》(作者:陈志旺等) 一书看到

利用异或

#include <stdio.h>

int main()

{

int a = 21;

int b = 43;

a = a ^ b;

b = b ^ a;

a = a ^ b;

printf("a = %d,b = %d\n",a,b);

return 0;

}



0 0
原创粉丝点击