C中取消引用和括号引用的操作顺序

时间:2010-08-24 01:00:48

标签: c pointers pointer-arithmetic

如果我*ptr[x],那是相当于*(ptr[x])还是(*ptr)[x]

3 个答案:

答案 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])