If I do *ptr[x]
, is that equivalent to *(ptr[x])
, or开发者_如何学Python (*ptr)[x]
?
*(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])
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])
精彩评论