+= and -=

Jan 8, 2010 at 4:20pm
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!
Jan 8, 2010 at 4:24pm
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;
Jan 8, 2010 at 4:36pm
Compound assignment operator. As blackcoder noted,
x += y
is the same as
x = x + y
Jan 8, 2010 at 9:48pm
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.
Jan 8, 2010 at 10:01pm
There are also other: %= >>= <<= &= ^= |=
http://www.cplusplus.com/doc/tutorial/operators/
Jan 8, 2010 at 10:03pm
You should have include
1
2
3
4
5
6
%=
<<=
>>=	
&=
^=
|=

too.

EDIT damn
Last edited on Jan 8, 2010 at 10:03pm
Jan 8, 2010 at 10:05pm
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?)
Jan 8, 2010 at 10:16pm
(I presume that the last five are bitwise?)

Correct
Topic archived. No new replies allowed.