I had come across this answer to this question. In one of the line, the author mention's:
In any case, follow the guideline "prefer
++i
overi++
" and you won't go wrong.
I know that ++i
is slightly faster than i++
, but thought that there is no reason for them to go wrong. I searched for a while, and the closest I could get to was this. It explained clearly that why is it preferred to use ++i
, but not still how could you go wrong using i++
.
So can anyone tell me how can i++
go wrong?
NOTE: My question isn't a dupe, as I am not asking about the performance. I have already seen that question. I am asking how can i++
be wrong as mentioned in the answer I have mentioned above.
i++
has to store the old value, while++i
does not. So the time storing it is saved. See: Is there a performance difference between i++ and ++i in C? – Giltzow++i
andi++
must have been discussed a gazillion times... – Samothracei++
being the more common. Andi++
is used in section 3.5 where thefor
loop is formally introduced. So I think the answer you quoted is a little biased, and the author is just promoting his preferred style. – Racerarray[++i]
is equivalent to(array+1)[i++]
and the latter is equally capable of being done in parallel. – Indonesia