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

Recommended Answers

All 5 Replies

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

http://www.difranco.net/cop2220/op-prec.htm


.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.