+ 1
How to swap two variables without using temp variable?
7 ответов
+ 3
a = a + b;
b = a - b;
a = a - b;
You can check it with two values.
+ 9
You can also use the XOR swapping algorithm.
X := X XOR Y
Y := Y XOR X
X := X XOR Y
+ 3
https://code.sololearn.com/cRlRP41C5vzn/?ref=app
0
a,b = b,a
This can swap two variables
0
I know that it works in javascript
0
@antonie it works for ruby too