next up previous contents index
Next: Declaring and using functions Up: Programming in C Previous: The break, continue and   Contents   Index


Shorthands

C offers the programmer shortened versions of common statements:

  
a += b;  /* equivalent to a = a + b  */
a -= b;  /* equivalent to a = a - b  */
a *= b;  /* equivalent to a = a * b  */
a /= b;  /* equivalent to a = a / b  */
a &= b;  /* equivalent to a = a & b  */
a |= b;  /* equivalent to a = a | b  */
a ^= b;  /* equivalent to a = a ^ b  */
A useful syntax for small if constructions is the expression

  
b ? c : d  /*  evaluates to c if b is true, and d otherwise  */
Another very common syntax is the expression i++. This evaluates to i, but then increments i by 1, and ++i which first increments i, and then returns the new value. i can be decremented using the expressions i-- and --i, which behave analogously.



CATAM admin 2010-02-23