#### 4.7.6 Operator Associativity

In Table 4-1 , the column labeled A specifies the associativity of the operator. A value of L specifies left-to-right associativity, and a value of R specifies right-to-left associativity. The associativity of an operator specifies the order in which operations of the same precedence are performed. Left-to-right associativity means that operations are performed from left to right. For example, the subtraction operator has left-to-right associativity, so:

w = x - y - z;

is the same as:

w = ((x - y) - z);

On the other hand, the following expressions:

x = ~-y; w = x = y = z; q = a?b:c?d:e?f:g;

are equivalent to:

x = ~(-y); w = (x = (y = z)); q = a?b:(c?d:(e?f:g));

because the unary, assignment, and ternary conditional operators have right-to-left associativity.

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/31322.html