Operator associativity

Operatorassoziativität referred especially in computer science, but also in mathematics and logic:

For example, in mathematics, the addition and multiplication associative operators, and because is. In the logic, for example, conjunction and disjunction is associative, because on the one hand and and on the other hand, and equivalent. Non- associative, for example Division and conditional, because in general, and because and are not equivalent.

Only for non- associative links the result of the Operatorassoziativität depends. To avoid that expressions with side by side, equivalent operators are ambiguous without parentheses, associativity is determined by convention:

  • A left- associative operator is evaluated from left to right. An example is the subtraction: it is.
  • The Division is left-associative:
  • The conditional in the logic used by most authors left-associative, which means that as we read.
  • A right- associative operator is evaluated from right to left. Examples: The potentiation in mathematics:
  • The assignment operator of various programming languages ​​such as C:   is equivalent, that is, the variable is initially assigned the value of and the result of the assignment ( which the assigned value is the same) then assigned.

In programming languages ​​which allow for side effects in terms of, the order / are carried out in this side-effects effective, important. Some programming languages ​​present this evaluation order strictly fixed, others (such as C or C ) allow the order of evaluation in most infix operands undefined. example:

Int f1 ( void); int f2 ( void); int f3 (void); int g ( int);   int h (void ) {    return g ( f1 () - f2 () - f3 ()); } It is not defined whether first f1, f2, f3 or be executed ( and thus their side effects are effective). In contrast, stipulates that g is called only after f1, f2 and f3 are complete ( with their side effects). The argument of g is identical to (f1 () f2 ()) - f3 (). see also

  • Operator Precedence
  • Programming
514321
de