The difference between the priority and the binding of operators in C language

Source: Internet
Author: User
Introduction: "C and Pointers" P83 page has such an example: A*b+c*d+e*f, and on this example, the operator's precedence and binding are explained. To facilitate the following instructions, we numbered the operators in the above expression separately: multiplication 1, 2, 3, plus 1, 2 for the precedence of operators I can also understand that the adjacent operators (such as multiplication 1 and plus 1 are adjacent, plus 1 and multiplication 2 adjacent ...). ) are evaluated in order of precedence and executed first. This so-called "adjacency" is for a variable (such as B or C in the expression above).
question: But for the combination of operators, I don't quite understand. The book explains "binding": "The two adjacent operators which first executes depends on their priority, and if they have the same priority, their order of execution is determined by their binding." The adjacent and priority operators are said to refer to two "plus" in the above expression. But the two "plus signs" at first glance are not adjacent ah, then how to define the adjacent sex.
My understanding: We should look at this problem of proximity with a dynamic perspective. In the above expression, for example, multiplication 1 and multiplication 2 will execute first and then generate a new value (assuming G and H), then the above expression becomes: g+h+e*f; At this point, the plus sign on both sides of H, is the adjacent operator .... The broader explanation is that the "adjacency" in "adjacent operators" is for an expression, for example, for the expression c*d, then the plus 1 and the plus 2 are adjacent. Then this explanation is not accurate.
further understanding: in fact, "priority" and "binding" are two different levels of the concept. Priority determines the order in which operators are executed, defines the order of time, and "associativity" determines the direction of the operator's execution and defines the spatial order. Take G+h+e*f as an example: from a priority point of view, the plus 2 has a lower priority than multiplication; From a binding perspective, the plus 1 and 2 should follow from left to right. Therefore, the final requirement is the plus 2 final implementation, as for the first plus 1 or multiplication operation, there is no inevitable stipulation.
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.