Lugaru's Epsilon
Programmer's
Editor 14.00 Previous Up Next Simple Binary Operators Epsilon Extension Language Function Calls

### Assignment Operators

expression:
expression `=` expression
expression modify-operator expression

modify-operator:
`+=`
`-=`
`*=`
`/=`
`%=`
`&=`
`|=`
`^=`
`<<=`
`>>=`

The plain assignment operator `=` takes an lvalue (see Constants and Identifiers) as its first operand. The object referred to by the lvalue is given the value of the second operand. The types of the operands may both be numbers, spots, pointers to the same type of object, or compatible structures. If the first operand is a pointer or spot and the second is the constant zero, the pointer or spot is made null. The value of the expression is the new value of the first operand, and it has the same type.

The other kinds of assignment operators are often used simply as abbreviations. For example, if `a` is a variable, `a += (b)` is the same as `a = a + (b)`. However, the first operand of an assignment is only evaluated once, so if it has side effects, they will only occur once.

For example, suppose `a` is an array of integers with values 10, 20, 30, and so forth. Suppose `p()` is a function that will return a pointer to the first element of `a` the first time it's called, then a pointer to the second element, and so forth. After the statement `*p() += 3;`, `a` will contain 13, 20, 30. After `*p() = *p() + 3;`, however, `a` is certain not to contain 13, 20, 30, since `p()` will never return a pointer to the same element of `a` twice. Because the order of evaluation is unspecified with these operators, the exact result of the latter statement is undefined (either 10, 13, 30 or 23, 20, 30).

The result of all these assignment statements is the new value of the first operand, and will have the same type. The special rules for mixing pointers and ints with the `+` and `-` operators also apply here.

 Previous Up Next Simple Binary Operators Epsilon Extension Language Function Calls  Epsilon Programmer's Editor 14.00 manual. Copyright (C) 1984, 2020 by Lugaru Software Ltd. All rights reserved.