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..
How can 'i' be a condition?Code:if (i)
{ etc etc etc }
Printable View
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..
How can 'i' be a condition?Code:if (i)
{ etc etc etc }
- L += R;
Equivalent to:
Code:L = L + R;
- L -= R;
Equivalent to:
Code:L = L - R;
The operator != itself returns 1 or 0, so when you use
it's like you're usingCode:if(x != 0)
orCode:if( (x != 0) != 0)
ad infinitum. So you can just leave out the first != 0 and goCode:if ( (x != 0) != 0) != 0)
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 goCode:if(x)
or evenCode:int x = 1, y = x != 0;
if(y)
instead ofCode:if(x)
. . . okay, so that wasn't a very good explanation. But I hope you know what I mean. :)Code:if(x != 0)
lol... Funny way of putting itQuote:
or
Code:
if ( (x != 0) != 0) != 0)
ad infinitum. So you can just leave out the first != 0 and go
Code:
if(x)
I know, it's definitely a novel idea. :D
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:
http://books.google.com/books?id=svQ...nidOjt7qKR7yl8