| annmtui (2) | |
|
#include <iostream.h> int main() { int x=99; if(x++<100) { cout<<"it is false"; } else { cout<<"it is true"; } return 0; } i wonder why if i try to run this it gives me false even when i change the < to> and if i try to cout at the end the x++ it gives me 99 and when i channge and incrimate it at the end it gives me 100 also if i change the false to true it starts displaying true | |
|
|
|
| Mathhead200 (948) | ||||
|
x++ means x = x + 1, but return the old x value. ++x means x = x + 1, but return the new x value.
And, why is this posted under "articles"? | ||||
|
Last edited on
|
||||
| L B (3325) | ||
I wish the C++ tutorial on this site was more clear about it returning the old value via making a copy before increment; it currently makes it sound like post-increment is multi-threaded and doesn't involve making a copy:
| ||
|
|
||
| firedraco (5413) | |
| I don't think it sounds like that...but I do think it's confusing. | |
|
|
|