简体   繁体   English

从表中了解运算符优先级

[英]Understanding operator precedence from the table

I was going over the following link and it states 我正在浏览以下链接 ,它指出

Operators between dashed lines have the same "precedence level", of which you will note that there are 18 虚线之间的运算符具有相同的“优先级”,您会注意到其中有18个

Now my question is what does the above statement mean. 现在我的问题是以上陈述是什么意思。 For instance if two operators are between the dashed lines like -> comes before [] does this mean -> has higher precedence than [] ? 例如,如果两个运算符位于虚线之间,例如->出现在[]之前,是否意味着->优先级高于[]

For instance if two operators are between the dashed lines like -> comes before [] does this mean -> has higher precedence than [] ? 例如,如果两个运算符位于虚线之间,例如->出现在[]之前,是否意味着->优先级高于[]

Yes, both are at same precedence level but because of Left to right associativite for example: 是的,两者都处于相同的优先级,但是由于从左到右的关联,例如:

a->b[i];

is parsed or equivalent as (a->b)[i]; 被解析或等效为(a->b)[i]; . This is useful when a is a pointer to structure and b is a array member of struct. a是指向结构的指针而b是struct的数组成员时,这很有用。

And an expression like: 像这样的表达式:

a[i]->b;  

same as (a[i])->b; (a[i])->b; . This is useful when a is an array of structure's pointers. a是结构的指针数组时,这很有用。

You don't need parenthesis. 您不需要括号。

For * , . 对于*. , -> , and [] operators you can read this answer "Pointer to structure" . ->[]运算符,您可以阅读此答案“结构指针”

Yes .. you are right.. also note that in case like when * and / comes in an expression,that's where associativity is considered... in such a case you have to evaluate from left to right... 是的..你是对的..也请注意,在类似*/出现在表达式中的情况下,这就是关联性的考虑...在这种情况下,您必须从左到右求值...

In a * b / c , the operation a * b is evaluated first and then / is evaluated. a * b / c ,首先评估运算a * b ,然后评估/

In a / b * c , the operation a / b is evaluated first and then * is evaluated. a / b * c ,首先评估运算a / b ,然后评估*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM