What does left-to-right associativity mean?

后端 未结 6 717
生来不讨喜
生来不讨喜 2020-12-29 21:23

I am confused about the definition of left-to-right and right-to-left associativity. I have also seen them called left associativity and right associativity and would like t

6条回答
  •  天命终不由人
    2020-12-29 22:07

    Left to right associativity of a operator means right side of operator should not have any operator of higher precedece(priority), but it can be of same priority. If there is any operator of higher priority on right side of our operator, then we have to solve it first.example:

    x = 2 + 3 * 3;
    

    Here, for + operator(left to right associativity), right side contains a operator * , which is of higher priority than + operator, so we have to solve it first.

    x = 2 + 9;
    x = 11;
    

提交回复
热议问题