Assignment Operators

An assignment operator assigns a value to its left operand based on the value of its right operand.
The basic assignment operator is equal (=), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x. The other assignment operators are usually shorthand for standard operations, as shown in the following table.

Shorthand operator Meaning
x += y x = x + y
x -= y x = x - y
x *= y x = x * y
x /= y x = x / y
x %= y x = x % y
x <<= y x = x << y
x >>= y x = x >> y
x >>>= y x = x >>> y
x &= y x = x & y
x ^= y x = x ^ y
x |= y x = x | y

In unusual situations, the assignment operator is not identical to the Meaning expression in Table 3. When the left operand of an assignment operator itself contains an assignment operator, the left operand is evaluated only once. For example:

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.