+= and -=

Can somebody give me a quick explanation on what they mean and how they work? Thanks!

PS I have looked around and cant find it!
1
2
3
int number = 8;
number+=2;
number-=3;


is equal to

1
2
3
int number = 8;
number = number+2;
number = number-3;
Compound assignment operator. As blackcoder noted,
x += y
is the same as
x = x + y
also note that

1
2
3
4
x += y      
x -= y                      
x *= y                    
x /= y 


is same as:

1
2
3
4
x = x + y
x = x - y
x = x * y
x = x / y


respectively.
There are also other: %= >>= <<= &= ^= |=
http://www.cplusplus.com/doc/tutorial/operators/
You should have include
1
2
3
4
5
6
%=
<<=
>>=	
&=
^=
|=

too.

EDIT damn
Last edited on
Exactly right. You can find *anything* to do with C++'s standard and language parts here on this website's references.
(I presume that the last five are bitwise?)
(I presume that the last five are bitwise?)

Correct
Topic archived. No new replies allowed.