当前位置: 动力学知识库 > 问答 > 编程问答 >

brackets and points order in language c

问题描述:

I wonder in language c, is a.b[i] is the same thing as (a.b)[i] ?

Here a is a structure and b is his member (b is an array or a pointer).


I read an article about precedence of c operators just now and it told me that the [ ] (brackets) operator is prior to the .(point), and the associativity of these two c operators is left-to-right :


So what is the order of the following expression (in c)?

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

网友答案:

Operators . and [] have the same precedence, and are evaluated from left-to-right. The expression a.b[i] is the same as (a.b)[i]

The expression a.b.c[i].d[j] is evaluated as: ((((a.b).c)[i]).d)[j]

分享给朋友:
您可能感兴趣的文章:
随机阅读: