Exchange two variables without a third temporary variable.
Arithmetic (a=a+b; b=a-b; a=a-b) or XOR (a^=b; b^=a; a^=b) both avoid a temp. Caveats: arithmetic can overflow, XOR is integer-only, and both zero-out if the two operands are the same variable. In real code a temp (or destructuring/tuple swap) is clearer.
int a = 5, b = 9;
a = a + b; // 14
b = a - b; // 5
a = a - b; // 9let a = 5, b = 9;
[a, b] = [b, a]; // idiomatic, no temp
// arithmetic: a = a + b; b = a - b; a = a - b;a, b = 5, 9
a, b = b, a # tuple swap, no tempA pure trick question; the value is naming the failure modes (overflow, aliasing) — the "when does this break?" instinct of a strong tester.
A candidate gives the XOR swap. What happens for swap(x, x)?