http://en.cppreference.com/w/cpp/language/operator_precedence
You have a complex statement, Break it up into smaller statements using the order of precedence. It's an easy question. You'll get a is 0 even if you screw up the order of precedence.
You have three statements, not necessarily in this order. Study the order of precedence and stick them in the right order;
a += a;
a -= a;
a *= a;
Look at the the middle one.
a -= a;
It's the same as
a = 0;
So change to
a += a;
a = 0;
a *= a;
Now stick them in the right order. Or don't bother. Convince yourself that it's going to end up with a being 0 no matter what order you put them in and no matter what a's initial value is.
VernonDozier
Posting Expert
5,675 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 738
Skill Endorsements: 18
Your post was extreamly helpful. Thank you a lot.
You're welcome.
I just need to remember that * / % comes before + and -.
True, but irrelevant to this particular problem. You aren't dealing with *, +, -, where * takes precedence. You're dealing with *=, -=, +=, which all have the same precedence and evaluate right to left, so "a *= a += a" is going to be
a += a;
a *= a;
since += is to the right of *=.
VernonDozier
Posting Expert
5,675 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 738
Skill Endorsements: 18