Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - A is an integer 12. What is the result of this operation? a+=a-=a*=a? The answer is 0. I don't quite understand how to get 0.
A is an integer 12. What is the result of this operation? a+=a-=a*=a? The answer is 0. I don't quite understand how to get 0.
This assignment operation (such as: =,+=,-=, * =,/=,% =, etc. ) is operated from right to left, so you have to calculate the expression a*=a first, which is equivalent to: a = a * a =12 *12 =144.

Then calculate a-=a, which is equivalent to: a=a-a= 144- 144=0.

Finally, calculating a+=a is equivalent to: a=a+a=0+0=0.

So there is nothing wrong with the result being equal to 0.

You may not remember the priority and combination of operators, so you get the wrong result, or forget that the value of a is not the original 12 after an operation.