# Very quick, easy question

• 07-26-2005
Codefish
Very quick, easy question
What does x++ mean exactly? The effect it has seems to be to add one to x, but I don't know if that's its only use.
Code:

```for ( int x = 0; x < 10; x++ ) { etc...```
• 07-26-2005
Sucur
That is same like x = x +1
• 07-26-2005
Codefish
So "++" is exactly the same as "+ 1" in all circumstances?
• 07-26-2005
XSquared
No, it isn't. For example, take the following statements:
Code:

```int x = 1; int a = (x = x + 1);```
and
Code:

```int x = 1; int b = x++;```
In both cases, x will be 2 at the end of exection, but in the first example, a will have a value of 2, because it evaluates (x=x+1) first, and then assigns the value of x to a. In the second example, b will have the value of 1, because it assigns the value of x to b, and then adds 1 to x.
• 07-26-2005
ILoveVectors
Code:

```                int i3 = 1;         cout << i3++ << endl;         cout << i3 << endl;         i3 = 1;         cout << ++i3 << endl;         cout << i3 << endl;```
This is where these make a difference.
• 07-26-2005
dpro
More concisely(I think).

x++ does indeed mean x+1, however its the order that matters.

------
Example:

++x means, immediately increment x and use it as it was modified

x++ means, use x now and then increment it
• 07-26-2005
DougDbug
Just to add to the confusion...
Code:

```int x = 1;        int b = x++;    // b = 1, x = 2  (postfix, increment after assignment) int c = ++x;    // c = 3, x = 3  (prefix,  increment before assignment)```

Code:

```int x = 10;        int b = x--;    // b = 10, x = 9  (postfix, decrement after assignment) int c = --x;    // c = 8, x = 8  (prefix,  decrement before assignment)```
• 07-26-2005
Rashakil Fol
x++ is equivalent to something, it's just that it's

Code:

```x++    <->    (x = x + 1, x - 1) ++x    <->    (x = x + 1) x--    <->    (x = x - 1, x + 1) --x    <->    (x = x - 1)```
Note that the comma operator evaluates the expression on the left, then evaluates the expression on the right, and returns that value.
• 07-26-2005
Prelude
>So "++" is exactly the same as "+ 1" in all circumstances?
x++ and ++x have the same effect as x = x + 1...until you put them in a more complex expression. Once you do that, you can read ++x and x++ as "Oh my god! I just had demons fly out my nose!". That should protect you until you know better. ;)
• 07-26-2005
XSquared
>"Oh my god! I just had demons fly out my nose!"
Thanks a lot, Prelude. Milk just flew outta my nose... *cries*
• 07-26-2005
dpro
I have yet to proclaim "Oh my god! I just had demons fly out my nose!" I guess I am not pre and post incrementing correctly then :).

Anyway as for the OP I think he has enough answers to repel those demons from flying out his nose for the time being.