c - c语言中的括号和点顺序

标签 c expression operator-precedence

我想知道在 c 语言中,a.b[i] 是否与 (a.b)[i] 相同?

这里的a是一个结构体,b是他的成员(b是一个数组或者指针)。
我刚才读了一篇关于 c 运算符优先级的文章,它告诉我 [ ](括号) 运算符在 .(点) 之前,而 这两个 c 运算符的关联性是从左到右:

那么下面的表达式(c)的顺序是什么?

a.b.c[i].d[j]

最佳答案

运算符 .[] 具有相同的优先级,并且从左到右计算。表达式 a.b[i](a.b)[i]

相同

表达式 a.b.c[i].d[j] 的计算结果为:((((a.b).c)[i]).d)[j]

关于c - c语言中的括号和点顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37565386/

相关文章:

c - Eclipse 中的 printf

c - node *node1 与 node* node1 有什么区别?

c - 该程序不适用于 n > 9 ...当 n 是静态表达式时它工作正常

c - "if an int can hold all values of the original type then the value is converted to int , else to unsigned int"——什么意思?

Ruby && 和 = 运算符的误解

比较 int 与 long 和其他

c# - 组合两个表达式 (Expression<Func<T, bool>>)

C# MVC 模型表达式到值

wolfram-mathematica - Mathematica-为什么TreeForm [Unevaluated [4 ^ 5]]评估4 ^ 5?

java - 强制顺序优先(右结合)