#include <iostream>
using namespace std;
int main()
{
int x = 5, y = 5;
cout << x-- << " " << --y ;
// Outputs 5 4
return 0;
}
int b, a, e, d, c, f;
int num = 57;
cout << "The number is " << num << endl;
b = ++num;
a = ++num;
e = a + 1;
cout << "After post increment by 1, the number is " << b << endl;
cout << "After pre increment by 1, the number is " << a << endl;
cout << "After increasing by 1, the number is " << e << endl;
d = --e;
c = --e;
f = c - 1;
cout << "After post decrement by 1, the number is " << d << endl;
cout << "After pre decrement by 1, the number is " << c << endl;
cout << "After decreasing by 1, the number is " << f << endl;
Example 5-24. Overloading the increment operator
enum status { stopped, running, waiting };
status& operator++(status& s) { // Prefix
if (s != waiting)
s = status(s + 1);
return s;
}
status operator++(status& s, int) { // Postfix
status rtn = s;
++s;
return rtn;
}
int main( )
{
status s(stopped);
++s; // Calls operator++(s);
s++; // Calls operator++(s, 0);
}
int x = 5;
x--;
cout << x << endl;
//outputs 4