C type casts and addition precedence

我怕爱的太早我们不能终老 提交于 2019-12-29 06:36:07

问题


What's the precedence in the next expression?

item = (char*)heap + offset;

Is it (char*)(heap + offset) or ((char*)heap) + offset?


回答1:


Cast trumps binary addition according to the precedence table.




回答2:


It's ((char *)heap) + offset. Casts have much higher precedence than addition.




回答3:


((char*)heap) + offset



回答4:


The cast is done first, since it has a much higher precedence. You can look that up in the C precedence table!



来源:https://stackoverflow.com/questions/3354446/c-type-casts-and-addition-precedence

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