C type casts and addition precedence

前端 未结 4 932
甜味超标
甜味超标 2020-12-15 17:51

What\'s the precedence in the next expression?

item = (char*)heap + offset;

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

相关标签:
4条回答
  • 2020-12-15 18:03

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

    0 讨论(0)
  • 2020-12-15 18:12

    Cast trumps binary addition according to the precedence table.

    Precedence Table

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

    0 讨论(0)
  • 2020-12-15 18:22
    ((char*)heap) + offset
    
    0 讨论(0)
提交回复
热议问题