OPERATORS:
=
The
basic assignment operator is the equal sign, which assigns the value (literal
or variable) on its right to the variable on its left:
Code:
x = a;
The assignment operator can also be combined with a variety of other
operators to provide shorthand versions of standard operations. It combines
with the arithmetic operators +, -, *, /
and % to give the following shorthand versions:
a += b instead of a
= a + b
a -= b instead of a
= a - b
a *= b instead of a
= a * b
a /= b instead of a
= a / b
a %= b instead of a
= a % b
It also combines with the following bitwise operators:
a <<= b instead of a
= a << b
a >>= b instead of a
= a >> b
a >>>= b instead of a
= a >>> b
a &= b instead of a
= a & b
a ^= b instead of a
= a ^ b
a |= b instead of a
= a | b
NOTE:
If the operand to the left of the equal sign itself contains an assignment
operator, then the above shorthand statements won't work. Instead you
must use the longer version of the statement.
|