// // Filename: pgm2_4a.cpp // // Description: Example of C++ pre and post increment operators. // // ENSC 104: Digital Computer Programming // // Instructor: Dr. Walsh // // Section: 2 // // Date Created: 02/14/98 // Last Modified: 02/14/98 // // Name: N/A // #include main() { int x = 2; int y = 3; cout << "Post increment!\n"; cout << "x = " << x << endl; cout << "x = " << x++ << endl; cout << "x = " << x << endl << endl; cout << "Pre increment!\n"; cout << "x = " << x << endl; cout << "x = " << ++x << endl; cout << "x = " << x << endl << endl; x += y++; cout << "x = " << x << endl << endl; x = 2; y = 3; x += ++y; cout << "x = " << x << endl << endl; x = 2; cout << "Condition equates to: " << ( x == 2 ) << endl; cout << "Condition equates to: " << ( x == 3 ) << endl << endl; // COMPILE ERROR! cout << "Condition equates to: " << x == 2 << endl; x = 2; y = 3; if ( x-- == (y-=1) ) cout << "True: X = " << x << ", Y = " << y << endl; else cout << "False: X = " << x << ", Y = " << y << endl << endl; return 0; }