Why makes it no difference between using "x++" or "++x" as increment in a for loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why makes it no difference between using "x++" or "++x" as increment in a for loop?

31st Jul 2016, 10:50 PM
Marco Neumann
Marco Neumann - avatar
2 Answers
+ 1
They are very different. While x++ returns the value of the variable x and then increments x by 1, ++x will increment variable x by 1 and then return the new value (ie. return x + 1). int x = 0; printf("x++ is %d, ++x is %d", x++, ++x); Output: x++ is 0, ++x is 1
30th May 2017, 6:12 AM
Chuma Umenze
0
because inside the for loop that statement is final, no matter if its post-fix or pre-fix by the end of the statement, it increments regardless.
3rd Aug 2016, 1:41 AM
Dmitry
Dmitry - avatar