Can someone inform me on what the "-=" function does? thanks.

5
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by WaltP

Can someone inform me on what the "-=" function does? thanks.

It is not a function is an arithmetic operator and assignment operator short cut.
number -= x;
same as
number = number - x;

ahh i c. So rem-=50 is rem = rem-50? and rem+=50 = rem=rem+50? I'm a complete noob to programming and with an instructor who assumes the class is on his level when 3/4 isn't learning all this from scratch is a bit intense so I might show up with stupid questiosn from time to time. Thanks.

ahh i c. So rem-=50 is rem = rem-50? and rem+=50 = rem=rem+50? I'm a complete noob to programming and with an instructor who assumes the class is on his level when 3/4 isn't learning all this from scratch is a bit intense so I might show up with stupid questiosn from time to time. Thanks.

Yes, that's what rem -= 50 and rem += 50 are.

and here's a bunch more:

``=     +=     -=     *=     /=     %=     <<=     >>=     &=     ^=     |=``

"a *= 4 " is the same as "a = a * 4"
"b <<= 1" is the same as "b = b << 1".

in other words, multiply 'a' by 4 and put the result back in 'a'. ... shift 'b' left by one bit, and put the result back into 'b'.

one main thing to be aware of is "operator precedence". any statement that has more than one operator, the order of operations is strictly defined. so in C/C++, the following two expressions are the same:

ans = a + b * c;

ans = a + ( b * c );

but are completely different than

ans = ( a + b ) * c;

you can find a list of "operator precedence" most anywhere

.

Gee guys, are we rewriting the text book? :icon_wink:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.