编程技巧 - 变量互换

上官梦舞 / 2023-08-13 / 原文

一般做法

int a,b;
int temp;

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

  巧妙方法

int a,b;

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

  这样就不需要第三个变量