本帖最后由 福禄娃娃 于 2013-10-13 11:07 编辑
编译器不同,具体差距看反汇编结果
你的为 p = 5 +5 +5 =15 i用完再自增为8
q= 7+ 7+ 8 =22 j先自增两次,前两项然后相加,j再自增一次,第三项和前面的值相加。j为8
在VC或者VS中F9下个断点,然后F5调试,Alt+8查看反汇编代码
下面是反汇编代码5: int i = 5,j = 5,p = 0,q = 0;
00401028 mov dword ptr [ebp-4],5 i = 5
0040102F mov dword ptr [ebp-8],5 j =5
00401036 mov dword ptr [ebp-0Ch],0
0040103D mov dword ptr [ebp-10h],0
6: p = (i++) + (i++) + (i++);
00401044 mov eax,dword ptr [ebp-4]
00401047 add eax,dword ptr [ebp-4] 5+5=10
0040104A add eax,dword ptr [ebp-4] 10+5=15
0040104D mov dword ptr [ebp-0Ch],eax
00401050 mov ecx,dword ptr [ebp-4]
00401053 add ecx,1 i自增一次 i = 6
00401056 mov dword ptr [ebp-4],ecx
00401059 mov edx,dword ptr [ebp-4]
0040105C add edx,1 i自增一次 i =7
0040105F mov dword ptr [ebp-4],edx
00401062 mov eax,dword ptr [ebp-4]
00401065 add eax,1 i自增一次 i = 8
00401068 mov dword ptr [ebp-4],eax
7: q = (++j) + (++j) + (++j);
0040106B mov ecx,dword ptr [ebp-8]
0040106E add ecx,1 j自增一次 j = 6
00401071 mov dword ptr [ebp-8],ecx
00401074 mov edx,dword ptr [ebp-8]
00401077 add edx,1 j自增一次 j = 7
0040107A mov dword ptr [ebp-8],edx
0040107D mov eax,dword ptr [ebp-8]
00401080 add eax,dword ptr [ebp-8] 7 + 7 = 14
00401083 mov ecx,dword ptr [ebp-8]
00401086 add ecx,1 j自增一次 j = 8
00401089 mov dword ptr [ebp-8],ecx
0040108C add eax,dword ptr [ebp-8] 14 + 8 = 22
0040108F mov dword ptr [ebp-10h],eax
|