Answer: Associativity comes in to the picture when we have same operators in an expression. It tells the order of evaluation that which operator should work first.
Binary operators are
left associative (executes from left to right).
Example,
4 + 3 + 2
In the above example, first the sum is performed between 4 and 3. Then the result will be summed to 2.
Assignment,
conditional,
lambda and
null coalescing operators are
right associative (executes from right to left).
Example,
x = y = z = 6
In the above example, 6 is first assigned to
z and then to
y and so on.
Asked In: Spotted While Learning |
Alert Moderator