/* testops2.cpp CIS 150 5/29/2008 David Klick Examples of increment and decrement operators. */ #include using std::cin; using std::cout; void cont(); int main(void) { // declare and initialize variables int x = 5; int y = 0; // display results of inc and dec operators cout << " y x\n"; cout << "at start: " << y << ", " << x << '\n'; y = ++x; cout << "after y = ++x: " << y << ", " << x << '\n'; y = x++; cout << "after y = x++: " << y << ", " << x << '\n'; y = --x; cout << "after y = --x: " << y << ", " << x << '\n'; y = x--; cout << "after y = x--: " << y << ", " << x << '\n'; cont(); return 0; } void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press Enter to continue..."; cin.get(); return; } /* Sample output: y x at start: 0, 5 after y = ++x: 6, 6 after y = x++: 6, 7 after y = --x: 6, 6 after y = x--: 6, 5 */