what is this with the incrimination in the if statement

#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
x++ means x = x + 1, but return the old x value.
++x means x = x + 1, but return the new x value.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

using namespace std;

int main() {
   int pre = post = 5;
   cout << ++pre << endl;
   cout << post++ << endl;
   cout << pre << endl;
   cout << post << endl;
   return 0;
}
6
5
6
6


And, why is this posted under "articles"?
Last edited on
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:
in case that it is used as a suffix (a++) the value stored in a is increased after being evaluated and therefore the value stored before the increase operation is evaluated in the outer expression.
It could be poor wording, as "stored" here is used in a way that could mean the correct thing, but it is unclear.
I don't think it sounds like that...but I do think it's confusing.
Topic archived. No new replies allowed.