Assignment Operators

Assignment operators assign a value to a left operand based on the value of a right operand. The basic assignment operators are described in the Assignment Operators table. The other assignment operators, described in the Shorthand Assignment Operators table, are shorthand for standard operations.

OperatorDescription

=

Assigns the value of the second operand to the first operand.

+=

Adds two numbers and assigns the result to the first.

-=

Subtracts two numbers and assigns the result to the first.

*=

Multiplies two numbers and assigns the result to the first.

/=

Divides two numbers and assigns the result to the first.

%=

Computes the modulus of two numbers and assigns the result to the first.

&=

Performs a bitwise AND and assigns the result to the first operand.

^=

Performs a bitwise XOR and assigns the result to the first operand.

|=

Performs a bitwise OR and assigns the result to the first operand.

>>=

Performs a sign-propagating right shift and assigns the result to the first operand.

>>>=

Performs a zero-fill right shift and assigns the result to the first operand.

Shorthand OperatorMeaning

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