0
What is the difference between ++x and x++?
3 Answers
+ 3
x++
value is used then incremented
++x
value is incremented then used
to be put simply
0
The difference lies in when x is actually incremented. Say you have:
int x = 0:
cout >> ++x; // Prints "1"
The output of this would print "1", because the + signs BEFORE the variable indicate that x should immediately increment. However, having + signs AFTER the variable tells the computer that it should increment x only after the computation is complete (once the program moves to the next line). Like so:
int x = 0;
cout >> x++; // Prints "0"
cout >> x; // Prints "1" since the computer remembered to increment
0
What's the difference between ++x and x++?



