Thoughts on operator priority and combination law in C Language

Source: Internet
Author: User

(1) B = * p ++;
(2) B = (* p) ++;
(3) B = ++ * p;
(4) B = ++ (* p );
(5) B = * ++ p;
(6) B = * (++ p );

Which of the above six statements are equivalent?

Disassembly code:

[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
Answer: (3) = (4), (5) = (6)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.