On a few processors, such as PDP-11, VAX-11 and 68K, there are modes for some instructions that do the equivalent of *ptr++
and *--ptr
. Depending on the exact way the code is written, it may or may not be easy for the compiler to utilize these instructions - so, using the "right" variant of *++ptr
or *ptr++
[which is better depends a bit on the usage in the actual loop] inside the loop can make a decent difference in performance in these particular cases. However, for ARM and x86 (and I think, PowerPC and MIPS, thus covering nearly all modern processors), this type of construct isn't part of the instruction set anyway, and compilers are a lot more clever these days than they were, say, 10 or 20 years ago.
Any reasonable compiler will do the same thing for basic types, the i++
or ++i
is not an issue.
If we have a "complicated" type, such as a struct or class with an operator++(int)
, and opterator++()
there may be a small difference [or in extreme cases, a big difference], because the object has to be copied. Say we have a bigmath
class, and our i
is a 1000 digit long value. Now we have to make a(n extra) copy of 1000 digits in the middle of the increment. If the compiler is able to "understand" what is going on, it may elide that copy, but it's not guaranteed to happen.