#include<iostream>
using namespace std;
int main()
{
int i=8;
/*i+=(i++);
cout<<i<<endl;*/
//result: 17
/*004113C5 mov eax,dword ptr [i]
004113C8 add eax,dword ptr [i]
004113CB mov dword ptr [i],eax
004113CE mov ecx,dword ptr [i]
004113D1 add ecx,1
004113D4 mov dword ptr [i],ecx */
/*i+=(++i);
cout<<i<<endl; */
//result: 18
/*004113C5 mov eax,dword ptr [i]
004113C8 add eax,1
004113CB mov dword ptr [i],eax
004113CE mov ecx,dword ptr [i]
004113D1 add ecx,dword ptr [i]
004113D4 mov dword ptr [i],ecx */
//(++i)+=(i++);
//cout<<i<<endl;
//result: 19
/*004113C5 mov eax,dword ptr [i]
004113C8 add eax,1
004113CB mov dword ptr [i],eax
004113CE mov ecx,dword ptr [i]
004113D1 add ecx,dword ptr [i]
004113D4 mov dword ptr [i],ecx
004113D7 mov edx,dword ptr [i]
004113DA add edx,1
004113DD mov dword ptr [i],edx*/
//(++i)+=1;
//cout<<i;
//result: 10
/*00413545 mov eax,dword ptr [i]
00413548 add eax,1
0041354B mov dword ptr [i],eax
0041354E mov ecx,dword ptr [i]
00413551 add ecx,1
00413554 mov dword ptr [i],ecx */
//(++i)=(++i)+1;
//cout<<i;
//result: 11
/*00413545 mov eax,dword ptr [i]
00413548 add eax,1
0041354B mov dword ptr [i],eax
0041354E mov ecx,dword ptr [i]
00413551 add ecx,1
00413554 mov dword ptr [i],ecx
00413557 mov edx,dword ptr [i]
0041355A add edx,1
0041355D mov dword ptr [i],edx*/
}
总的来说,比如(++i)=(++i)+1. 编译器先执行右边的++i, 先读取i的值,加1后写回。然后再执行左边的部分,读取i的值,加1后再写回。然后,再读取i的值,加1, 赋值给i。所以,最后i的值是11