home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 98.img / LCNOW2.ZIP / EXAMPLES / PRE&POST.C < prev    next >
C/C++ Source or Header  |  1988-02-19  |  682b  |  26 lines

  1. /*
  2.  * P R E & P O S T
  3.  *
  4.  * Demonstrate the uses of prefix and postfix notation
  5.  * in arithmetic expressions.
  6.  */
  7.  
  8. main()
  9. {
  10.     /* Initialize and declare variables */
  11.     int x = 2, y = 3, result;
  12.  
  13.     /* Show values before and after expression evaluation. */
  14.     printf("\nSTARTING VALUES: x=%d; y=%d\n", x, y);
  15.     result = ++x + y;
  16.     printf("PREFIX: The result of ++x + y = %d\n", result);
  17.     printf("(After calculation, x=%d and y=%d)\n", x, y);
  18.  
  19.     x = 2, y = 3;    /* Restore values */
  20.     printf("\nSTARTING VALUES: x=%d; y=%d\n", x, y);
  21.     result = x++ + y;
  22.     printf("POSTFIX: The result of x++ + y = %d\n", result);
  23.     printf("(After calculation, x=%d and y=%d)\n", x, y);
  24. }
  25.  
  26.