0

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

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 [] ?

Rajeshwar
  • 11,179
  • 26
  • 86
  • 158

2 Answers2

2

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];. This is useful when a is a pointer to structure and b is a array member of struct.

And an expression like:

a[i]->b;  

same as (a[i])->b;. This is useful when a is an array of structure's pointers.

You don't need parenthesis.

For *, ., ->, and [] operators you can read this answer "Pointer to structure".

Community
  • 1
  • 1
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
2

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.

In a / b * c, the operation a / b is evaluated first and then * is evaluated.

user3256147
  • 378
  • 2
  • 9