UMBC CS 201, Fall 98
UMBC CMSC 201 & 201H Fall '98 CSEE | 201 | 201 F'98 | lectures | news | help

Increment and Decrement Operators

It is so common to do things like:
  total = total + 1;     /* increment total */
that C provides a "shorthand" way of doing it:
  total++;              /* increment total */



++X vs. X++

--X and X-- work the same way, except 1 is being subtracted from X.

Example:

  x = 3;
  printf("The value of X is %d\n", ++x);  /* prints 4 */
  /* and the value of x is now 4 */
  printf("The value of X is %d\n", x++);  /* prints 4 AGAIN */
  /* but the value of x is now 5 */

Is all this a good idea?


CSEE | 201 | 201 F'98 | lectures | news | help

Monday, 07-Sep-1998 15:03:06 EDT