incremental operation issues

Hello,

This is probably a simple issue but I haven't programmed c++ in several years.
The incremental operator only seems to work one direction. It will add one for something like (++y) but not for (y++). As far as I remember it worked in both directions. Has this changed or is it a compiler-specific thing? I've tried a couple compilers (mingW and visual C++'s) and the results are the same.
Obviously it isn't a huge issue since it still works in the opposite direction. I'm just wondering what other changes have happened in the meantime.

thanks,
~mark
Those are not identical operators. One is pre-increment (++x) and the other is post-increment (x++). The difference is pre-increment increments the value of the variable before the expression is evaluated, and so obviously post-increment increments the value after.

1
2
3
int x = 0;
cout << x++ << endl; // x is outputted to the console, and then incrememented
cout << x << endl;


The output for this program would be

0
1


Whereas pre-increment

1
2
3
int x = 0;
cout << ++x << endl; // x is incremented, and then displayed on the console
cout << x << endl;


The output would be

1
1
Ah, I completely forgot how that worked. Thanks for clarifying!

~mark
Topic archived. No new replies allowed.