有关C语言运算符优先级和结合律的思考
(1) b=*p++;
(2)b=(*p)++;
(3)b=++*p;
(4)b=++(*p);
(5)b=*++p;
(6)b=*(++p);
上面6式子,哪些是等价的?
反汇编代码:
[plain]
b=*p++;
00411BD9 mov eax,dword ptr [p]
00411BDC mov ecx,dword ptr [eax]
00411BDE mov dword ptr [b],ecx
00411BE1 mov edx,dword ptr [p]
00411BE4 add edx,4
00411BE7 mov dword ptr [p],edx
b=(*p)++;
00411BEA mov eax,dword ptr [p]
00411BED mov ecx,dword ptr [eax]
00411BEF mov dword ptr [b],ecx
00411BF2 mov edx,dword ptr [p]
00411BF5 mov eax,dword ptr [edx]
00411BF7 add eax,1
00411BFA mov ecx,dword ptr [p]
00411BFD mov dword ptr [ecx],eax
b=++*p;
00411BFF mov eax,dword ptr [p]
00411C02 mov ecx,dword ptr [eax]
00411C04 add ecx,1
00411C07 mov edx,dword ptr [p]
00411C0A mov dword ptr [edx],ecx
00411C0C mov eax,dword ptr [p]
00411C0F mov ecx,dword ptr [eax]
00411C11 mov dword ptr [b],ecx
b=++(*p);
00411C14 mov eax,dword ptr [p]
00411C17 mov ecx,dword ptr [eax]
00411C19 add ecx,1
00411C1C mov edx,dword ptr [p]
00411C1F mov dword ptr [edx],ecx
00411C21 mov eax,dword ptr [p]
00411C24 mov ecx,dword ptr [eax]
00411C26 mov dword ptr [b],ecx
b=*++p;
00411C29 mov eax,dword ptr [p]
00411C2C add eax,4
00411C2F mov dword ptr [p],eax
00411C32 mov ecx,dword ptr [p]
00411C35 mov edx,dword ptr [ecx]
00411C37 mov dword ptr [b],edx
b=*(++p);
00411C3A mov eax,dword ptr [p]
00411C3D add eax,4
00411C40 mov dword ptr [p],eax
00411C43 mov ecx,dword ptr [p]
00411C46 mov edx,dword ptr [ecx]
00411C48 mov dword ptr [b],edx
答案:(3)=(4),(5)=(6)
补充:软件开发 , C语言 ,