How do i apply the associativity rule? As in, do i start reading from the start or the back of the statement and then when i hit the first operator i start bracketting...
'=' is right to left associative, and that's the natural way to think about it. The right hand side is fully evaluated before the assignment can be made to the left hand side. That means you have:
i = ( j = k = 42);
Now look inside the brackets and apply the rule again.
i = ( j = (k = 42));
Addition is left to right associative. So it would mean (((a + b) + c) + d); By the way that's not a statement its an expression.
this may sound basic, but if i have statements:
i = j = k = 42;
and:
a + b + c + d;
How do i apply the associativity rule? As in, do i start reading from the start or the back of the statement and then when i hit the first operator i start bracketting...
Natasha26 2 years ago
'=' is right to left associative, and that's the natural way to think about it. The right hand side is fully evaluated before the assignment can be made to the left hand side. That means you have:
i = ( j = k = 42);
Now look inside the brackets and apply the rule again.
i = ( j = (k = 42));
Addition is left to right associative. So it would mean (((a + b) + c) + d); By the way that's not a statement its an expression.
Zantorc 2 years ago
thank you so much.
Natasha26 2 years ago