Yes, these are operators. More specifically, they are known as compound assignment operators. Here's the full list of them:
*= /= %= += -= >>= <<= &= ^= |=
They are defined like so:
The behavior of an expression of the form
E1 op = E2
is equivalent toE1 = E1 op E2
except thatE1
is evaluated only once.
So x += 5;
is almost the same as x = x + 5;
.
You can think of it as a modifying addition. If you just do x + 5
, the result of the expression is what you get if you add x
and 5
together, but x
hasn't changed. If you do x += 5;
, x
actually has 5 added to its value.