我把这段代码反汇编了一下,旁边每一句写了注释18: int x=1,y,z;
00401028 mov dword ptr [ebp-4],1 // x = 1
19: y=(++x)*(++x);
0040102F mov eax,dword ptr [ebp-4] // eax = x = 1
00401032 add eax,1 // ++eax = 2
00401035 mov dword ptr [ebp-4],eax // x = eax = 2
00401038 mov ecx,dword ptr [ebp-4] // ecx = x = 2
0040103B add ecx,1 // ++ecx = 3
0040103E mov dword ptr [ebp-4],ecx // x = ecx = 3
00401041 mov edx,dword ptr [ebp-4] // edx = x = 3
00401044 imul edx,dword ptr [ebp-4] // edx = x * edx = 3 * 3 = 9
00401048 mov dword ptr [ebp-8],edx // y = edx = 9
20: printf("%d",y);
0040104B mov eax,dword ptr [ebp-8] // print 9
意思就是 先计算 ++x 得到x = 2,然后 ++x 得到 x = 3,最后 3 * 3 = 9 |