+ 1
How to swap 2 variables value?
How to swap value of 2 variables without add 3rd variable ??
4 Respostas
+ 7
a += (b - (b = a));
works fine, and it's only 1 line of code!!😀
+ 3
a = a + b;
b = b - a;
b = -b;
a = a - b;
+ 3
@Kamil, @Yan: Great simplification of code. Watch out when the variables don't have infinite precision, though –you could be lead to accuracy issues.
0
@Kamil, great and simple,
@Kamil @Yan Markov, thanks...