编程技巧 - 变量互换

一般做法

int a,b;
int temp;

temp = a;
a = b;
b = temp;

  巧妙方法

int a,b;

a = a^b;
b = a^b;
a = a^b;

  这样就不需要第三个变量

posted @ 2023-08-13 18:52  上官梦舞  阅读(8)  评论(0编辑  收藏  举报