home *** CD-ROM | disk | FTP | other *** search
- /*
- C++ program illustrates the feature of the increment operator.
- The ++ or -- may be included in an expression. The value
- of the associated variable is altered after the expression
- is evaluated if the var++ (or var--) is used, or before
- when ++var (or --var) is used.
- */
-
- #include <iostream.h>
-
- main()
- {
- int i, k = 5;
-
- // use post-incrementing
- i = 10 * (k++); // k contributes 5 to the expression
- cout << "i = " << i << "\n\n"; // displays 50 (= 10 * 5)
-
- k--; // restores the value of k to 5
-
- // use pre-incrementing
- i = 10 * (++k); // k contributes 6 to the expression
- cout << "i = " << i << "\n\n"; // displays 60 (= 10 * 6)
- return 0;
-
- }
-