C - What is the difference between ++i and i++ ?
++i will increment the value of i, then return the incremented value.
Tue Dec 15 13:06:34 2015 - permalink -
i++ will increment the value of i, but return the original value that i held before being incremented.
In 'for' loops, both '++i' and 'i++' will produce the same number of loops, provided i is increment within the 'for' construct itself :
for (i=0; i<10; i++)
for (i=0; i<10; ++i)
for(i=0; i<5; i++)
for(i=0; i<5; ++i)
will both produce the same output : 0 1 2 3 4.
for(i = 0; i<5;)
In this case output will be 1 2 3 4 5.
NB : Please don't worry about the "efficiency" (speed, really) of which one is faster. We have compilers these days that take care of these things. Use whichever one makes sense to use, based on which more clearly shows your intent.