Order of operations for dereference and bracket-ref in C

隐身守侯 提交于 2019-11-27 04:38:45

*(ptr[x])

See the Wikipedia operator precedence table, or, for a more detailed table, this C/C++ specific table.

In C, all postfix operators have higher precedence than prefix operators, and prefix operators have higher precedence than infix operators. So its *(ptr[x])

t0mm13b

Using the counter-clockwise movement of analyzing and parsing that simple example

1. starting with ptr, work in counter-clockwise until you hit asterisk operator
2. asterisk, in counter-clockwise until you hit subscript operator
3. we arrive here, at subscript operator [x]

Since [] has higher precedence than the asterisk as per this table , that makes it *(ptr[x])

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