0

What is the difference between ++x and x++?

17th Aug 2016, 7:08 PM
Emmett N. Lipholo
Emmett N. Lipholo - avatar
3 Answers
+ 3
x++ value is used then incremented ++x value is incremented then used to be put simply
5th Nov 2016, 7:26 AM
Paul Birkholtz
Paul Birkholtz - avatar
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
22nd Aug 2016, 5:55 AM
Tataeus
Tataeus - avatar
0
What's the difference between ++x and x++?
10th Mar 2018, 7:50 AM
Marc Yvan Kevyn Marc
Marc Yvan Kevyn Marc - avatar