HP C/iX Reference Manual (31506-90011)
Chapter 5 85
Expressions
Assignment Operators
Assignment Operators
Assignment operators assign the value of the right operand to the object designated by the
left operand.
Syntax
assignment-expression
::=
conditional-expression
unary-expression assignment-operator assignment-expression
assignment-operator
:= one selected from the set
= *= /= %= += -= <<= >>= &= ^= |=
Description
Each assignment operator must have a modifiable lvalue as its left operand. An
assignment operator stores a value into the left operand. The C language does not define
the order of evaluation of the left and right operands. For this reason, you should avoid
operations with side effects (such as ++ or --) if their operands appear on both the left and
right side of the assignment. For example, you should not write an expression like the
following because the results depend on which operand is evaluated first.
*p++ = *p--
Simple Assignment
In simple assignment, the value of the right operand replaces the value of the object
specified by the left operand. If the source and destination objects overlap storage areas,
the results of the assignment are undefined.
The left and right operands can be any of the following combinations:
1. Both arithmetic
If both of the operands are arithmetic types, the type of the right operand is converted
to the type of the left operand. The converted value is then stored in the location
specified by the left operand.
2. Both structure/union
If both operands are structures or unions of the same type, the right structure/union is
copied into the left structure/union. A union is considered to be the size of the largest
member of the union, and it is this number of bytes that is moved.
3. Left operand is a pointer to type T
In this case, the right operand can also be a pointer to type T. The right operand is then
copied to the left operand.
The right operand can also be a null pointer constant or a pointer to void.
A special case of pointer assignment involves the assignment of a pointer to void to