+ 1
Difference between x %= y*2 and x = x % y * 2.
https://code.sololearn.com/cwtEgwvXipnm/?ref=app This code show the slimmed down version of line 16. However if I change it to x = x % y * 2; I get a different result. Why is this?
5 odpowiedzi
+ 1
In c++
Let's break it down
x%=y*2
x%=(y*2)
x=x%(y*2)
now for x=x%y*2
% has higher precedence than *
x=(x%y) *2
hope this helps.
0
yes, it does very much thank you. when its part of an equal sign, % is not taking part in the precedence race, but works more like an equal sign. Is this correct? and if so, is this also correct for all others like it? -=, += etc?
0
Yes it is known as shorthand notation and they work all same.
example:
a+=b is same as a=a+b
0
well thats not what i meant, cause weve basically just shown in the first example that they dont work the same as their counterpart if the equations have operator precedence involved
0
bump