home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
oper2.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-18
|
751b
|
27 lines
/*
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;
}