Cpp Operators

Difference between increment/decrement operators

#include <iostream>
 
int main()
{
        using namespace std;
 
        int x = 5;
        int y = ++x; // x is 6, and 6 is assigned to y
        cout << " x = " << x << endl;
        cout << " y = " << y << endl;
 
        int a = 5;
        int b = a++; // a is 6, and b is 5
        cout << " a = " << a << endl;
        cout << " b = " << b << endl;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.