# 补充：是否可以用异或的方式交换两个值？

a b

a = a ^ b 之后 a ^ b b
b = a ^ b 之后 a ^ b a ^ b ^ b = a
a = a ^ b 之后 a ^ b ^ a = b a

## 为什么使用临时变量效率更高？

1. 编译器会对使用临时变量这种方式进行优化；使用异或的方式，编译器无法进行优化。
2. 可以很好地利用现代计算机的指令并行计算体系

Most modern compilers can optimize away the temporary variable in the three-way swap, in which case it will use the same amount of memory and the same number of registers as the XOR swap and is at least as fast, and often faster. In addition to that, the XOR swap is completely opaque to anyone unfamiliar with the technique.