开发者

Explain how C evaluates this expression

x=4+2%-8;

This gives output=6 Please any开发者_如何学Goone explain how?


x=4+2%-8; is equivalent to x = 4 + (2 % -8); which gives x = 4 + 2 which is 6.

More: C Operator Precedence Table


If you check this precedence chart first mod is taken and then added to 4

so (2%-8) gives 2
then 2+4 = 6


Because the precedence of the operator % is the highest from the equation, the program first executes the operation 2 % 8 which is 2 and the adds this to 4.


Because you can not divide the number 2 by 8. so no division and the number itself(2) will be the output as for the modulus value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜