The first one iterates to 9
, the second iterates to 10
. That's all.
The pre-/post- increment operation makes no difference.
Un-optimized code generated for both versions:
for(int i = 0; i < 10; ++i)
00E517AE mov dword ptr [i],0
00E517B5 jmp wmain+30h (0E517C0h)
00E517B7 mov eax,dword ptr [i]
00E517BA add eax,1
00E517BD mov dword ptr [i],eax
00E517C0 cmp dword ptr [i],0Ah
00E517C4 jge wmain+53h (0E517E3h)
{
}
for(int i = 0; i <= 10; i++)
00E517E3 mov dword ptr [i],0
00E517EA jmp wmain+65h (0E517F5h)
00E517EC mov eax,dword ptr [i]
00E517EF add eax,1
00E517F2 mov dword ptr [i],eax
00E517F5 cmp dword ptr [i],0Ah
00E517F9 jg wmain+88h (0E51818h)
{
}
So, even here, there is no performance penalty. The fact that i++
is slower than ++i
is just not true (at least in this context, where it doesn't make a difference). It would be slower for, say int y = i++
, but in this case, the two would do different things, which is not the case here. The performance issue might have been valid on compilers from 20 years ago, but not anymore.