Jul 12

C has special shorthand that simplifies coding of certain type of assignment statements.

Example

a = a + 2;

can be written as

a + =2;     compound assignment statement

This operator  += tells the compiler that a is assigned the value of  a+2.

This shorthand works for all binary operators  in C.

General form:

<variable> < operator> = <variable/constant/expression>


Operator Example Meaning
+= a+=2 a=a+2
- = a-=2 a=a-2
*= a*=2 a=a*2
/= a/=2 a=a/2
%= a%=2 a=a%2
&&= a&&=c a=a&&c
||= a||=c a=a||c
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • LinkedIn
  • MySpace
  • Reddit
  • RSS
  • Twitter

written by Shweta