This seemed really interesting, so I took a peek at the disassembly (MSVC++2008)
k = (++i)+(++i);
0122413C mov eax,dword ptr [i]
0122413F add eax,1
01224142 mov dword ptr [i],eax
01224145 mov ecx,dword ptr [i]
01224148 add ecx,1
0122414B mov dword ptr [i],ecx
0122414E mov edx,dword ptr [i]
01224151 add edx,dword ptr [i]
01224154 mov dword ptr [k],edx
As you can see, it increments i
twice and then adds i
to itself. The same thing happens if there are multiple instances of (++i)
.
Anyway, since the Standard doesn't guarantee anything, modifying i
more than once will lead to undefined behaviour.