+ 5
How this swapping works?
b=a-b+(a=b)
5 Réponses
+ 2
ChillPill thanks
+ 2
Operator precedence is the key about this intelligent swap expression. The equal to '=' operator accumulates Right hand side expression, from right to left, parenthesis is evaluated first which overwrite a's memory location with vale inside variable b, 11 with moving left there is + and - arithmetic operators which has equal precedence yields 5, stores it in left hand side b=5. Nice work ChillPill
+ 2
This will assign the value of a to b. Since a=b ,the +b and -b will gets cancelled and results in b=a