5.1.4. Operator Associativity
As we've just learned, operator precedence indicates the
pecking order of operators: those with a higher precedence are
executed before those with a lower precedence. But what happens when
multiple operators occur together and have the same level of
precedence? In such a case, we apply the rules of operator
associativity, which indicate the direction of an
operation. Operators are either left-associative (performed left to
right) or right-associative (performed right to left). For example,
consider this expression:
a = b * c / d
The * and / operators are left-associative, so the
* operation on the left (b * c) is performed
first. The preceding example is equivalent to:
a = (b * c) / d
In contrast, the = (assignment) operator is right-associative, so the
expression:
a = b = c = d
says "assign d to c, then assign c to b, then assign b to
a," as in:
a = (b = (c = d))