如果我*ptr[x]
,那是相当于*(ptr[x])
还是(*ptr)[x]
?
答案 0 :(得分:14)
*(ptr[x])
请参阅Wikipedia operator precedence table,或者,更详细的表格this C/C++ specific table。
答案 1 :(得分:8)
在C中,所有后缀运算符的优先级都高于前缀运算符,前缀运算符的优先级高于中缀运算符。所以*(ptr[x])
答案 2 :(得分:-2)
使用逆时针运动分析和解析这个简单的例子
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]
由于[]
的优先级高于此table的星号,因此*(ptr[x])