HP C/iX Reference Manual (31506-90011)

86 Chapter5
Expressions
Assignment Operators
another pointer. No cast is necessary to convert a "pointer to void" to any other type of
pointer.
An assignment is not only an operation, it is also an expression. Each operand must have
an arithmetic type consistent with those allowed by the binary operator that is used to
make up the assignment operator. You can use the += and -= operators with a left operand
that is a pointer type.
Compound Assignment
Given the general assignment operator
op=
, if used in the expression
A
op
=B
the result is equal to the following assignment
A=A
op
(B)
except that the expression represented by A is evaluated only once.
Therefore,
A[f()] += B
is very different from
A[f()] = A[f()] + B
because the latter statement causes the function f() to be invoked twice.
Assignment operators are useful to reference complex subscript operators. For example:
a[j+2/i] += 3.5
In this case, the subscript expression is evaluated only once.
Examples
a += 5
Add 5 to a.
a *= 2
Multiply a by 2.
a = b
Assign b to a.
a <<= 1
Left shift a by 1 bit