开发者

C type casts and addition precedence

开发者 https://www.devze.com 2023-01-09 10:36 出处:网络
What\'s the precedence in the next expression? item = (char*)heap + offset; 开发者_高级运维 Is it (char*)(heap + offset) or ((char*)heap) + offset?Cast trumps binary addition according to the preced

What's the precedence in the next expression?

item = (char*)heap + offset;
开发者_高级运维

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


Cast trumps binary addition according to the precedence table.

C type casts and addition precedence


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


((char*)heap) + offset


The cast is done first, since it has a much higher precedence.

You can look that up in the C precedence table:

C type casts and addition precedence

0

精彩评论

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