# Thread: += and -=

1. ## += and -=

I've come across += and -= and have no clue as to what they do, and I cant find any tutorials either. Can anyone explain?

EDIT: I've also noticed some code..

Code:
```if (i)
{ etc etc etc }```
How can 'i' be a condition?

• L += R;

Equivalent to:

Code:
`L = L + R;`
• L -= R;

Equivalent to:

Code:
`L = L - R;`

2. Originally Posted by Sn0mAN
I've come across += and -= and have no clue as to what they do, and I cant find any tutorials either. Can anyone explain?

EDIT: I've also noticed some code..

Code:
```if (i)
{ etc etc etc }```
How can 'i' be a condition?
In C, everything non-zero is true (ie 0 is false). So if i is not 0, etc etc etc will be executed.

3. The operator != itself returns 1 or 0, so when you use
Code:
`if(x != 0)`
it's like you're using
Code:
`if( (x != 0) != 0)`
or
Code:
`if ( (x != 0) != 0) != 0)`
ad infinitum. So you can just leave out the first != 0 and go
Code:
`if(x)`
Every comparison operator (indeed, every operator) returns a zero or non-zero value. When you use if(x != 0), you're just using the zero or non-zero value value of x != 0. You can also use the zero or non-zero value of a variable. You could go
Code:
```int x = 1, y = x != 0;
if(y)```
or even
Code:
`if(x)`
Code:
`if(x != 0)`
. . . okay, so that wasn't a very good explanation. But I hope you know what I mean.

4. or
Code:

if ( (x != 0) != 0) != 0)

ad infinitum. So you can just leave out the first != 0 and go
Code:

if(x)
lol... Funny way of putting it

5. I know, it's definitely a novel idea.

6. With += and -= (or any of the compound assignment operators), the left-hand side is only evaluated once, instead of twice with the expanded form, so if its evaluation has a side effect, they're not equivalent (although this is uncommon).
Example: