Assignment Operators

assignment-expression:
        lvalue = expression
        lvalue += expression
        lvalue -= expression
        ++ lvalue
        lvalue ++
        -- lvalue
        lvalue --

There are three binary assignment operators, =, +=, and -=, all of which group right-to-left. All require an lvalue as their left operand. The right operand is evaluated and the value stored in the left operand after the assignment has taken place.

In the simple assignment with =, the value of the expression replaces that of the object referred to by the lvalue.

The behaviour of an expression of the form E1 op= E2 may be inferred by taking it as equivalent to E1 = E1 op (E2); however, E1 is evaluated only once. Both of the operands must be of integral types.

The object referred to by the lvalue operand of prefix ++ is incremented. The value is the new value of the operand, but is not an lvalue. The expression ++x is equivalent to x+=1.

When postfix ++ is applied to an lvalue the result is the value of the object referred to by the lvalue. After the result is noted, the object is incremented in the same manner as for the prefix ++ operator. The type of the result is the same as the type of the lvalue expression.

The lvalue operands of the prefix and postfix -- is decremented analogously to the prefix and postfix ++ operators respectively.

All the objects referred to by the lvalues of these assignment operators must be read/write variables, not formula variables.


[BACK] [FORWARD] [HOME] [UP] [HELP]