next up previous contents
Next: Type Equivalence Up: The MPD Programming Language Previous: References and Dereferences   Contents

Assignment Operators

The assignment operator = evaluates an expression and assigns its value to a variable. The form of an assignment is.

variable = expr

The type of the expression must be compatible with the type of the variable. Assignment is a right associative operator. thus, the following example

k = 89
j = k

can just as well be written

j = k = 89

Augmented assignment operators can sometimes simplify the writing of expressions. Their general form is

variable aug_op expr

The augmented operators are

**=  *=  /=  %/  +=  -=  &=  >>=  <<=  |=  ||=

Their meaning is derived from their base operator, with the following translation:

a @= b  -->  a = a @ b

where @ ranges over the base operators as listed above. Another group of convenient assignment operators are the increment and decrement operators. Their forms are

variable++    variable--    ++variable    --variable

The operators are known as postincrement, postdecrement, preincrement and predecrement, resp. The latter two first operates on the variable, returning the modified value while the former two returns the value of the variable before incrementing or decrementing. They may be used with ordered types, reals and pointers.


next up previous contents
Next: Type Equivalence Up: The MPD Programming Language Previous: References and Dereferences   Contents
David Sands 2003-09-05