Why do shifts have lower precedence than addition and subtraction in C?

我怕爱的太早我们不能终老 提交于 2019-12-19 19:54:13

问题


I sometimes find this inconvenient when doing bit manipulation (though I can't recall to mind any specific examples right now). I also find it conceptually confusing, since shifts are basically multiplication and division by powers of two.

I see that it can be convenient in C++, when using << to send output to an ostream, but of course that can't be used to explain how the order was originally fixed in C.


回答1:


Because that's what the authors of the C language decided.

Use parentheses to avoid confusion.



来源:https://stackoverflow.com/questions/9370844/why-do-shifts-have-lower-precedence-than-addition-and-subtraction-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!