This equation swaps two numbers without a temporary variable, but uses arithmetic operations:
a = (a+b) - (b=a);
How can I do it without arithmetic operations? I was thinking about XOR.
a=a+b; b=a-b; a=a-b;
This is simple yet effective....
2.1m questions
2.1m answers
60 comments
57.0k users