|C Tutorial||Other assignment operators|
Introduction to C language
Type combination and promotion
Floating point types
Int vs float arithmatic
Unary Increment Operators
Pre and Post Variations
C Programming Cleverness and Ego Issues
Other Assignment Operators
In addition to the plain = operator, C includes many shorthand operators which represents
variations on the basic =. For example "+=" adds the right hand side to the left hand side.
x = x + 10; can be reduced to x += 10;. This is most useful if x is a long expression such as the following, and in some cases it may run a little faster.
person->relatives.mom.numChildren += 2; // increase children by 2
Here's the list of assignment shorthand operators...
+=, -= Increment or decrement by RHS
*=, /= Multiply or divide by RHS
%= Mod by RHS
>>= Bitwise right shift by RHS (divide by power of 2)
<<= Bitwise left shift RHS (multiply by power of 2)
&=, |=, ^= Bitwise and, or, xor by RHS