When an expression contains two operators of equal priority the tie between them is settled using the associativity of the operators. Associativity can be of two types—Left to Right or Right to Left. Left to Right associativity means that the left operand must be unambiguous. Unambiguous in what sense? It must not be involved in evaluation of any other sub-expression. Similarly, in case of Right to Left associativity the right operand must be unambiguous. Let us understand this with an example.
Consider the expression
a = 3 / 2 * 5 ;
Here there is a tie between operators of same priority, that is between / and *. This tie is settled using the associativity of / and *. But both enjoy Left to Right associativity. Figure 1.10 shows for each operator which operand is unambiguous and which is not.
Since both / and * have L to R associativity and only / has unambiguous left operand (necessary condition for L to R associativity) it is performed earlier.
Consider one more expression
a = b = 3 ;
Here both assignment operators have the same priority and same associativity (Right to Left). Figure 1.11 shows for each operator which operand is unambiguous and which is not.
Since both = have R to L associativity and only the second = has unambiguous right operand (necessary condition for R to L associativity) the second = is performed earlier.
Consider yet another expression
z = a * b + c / d ;
Here * and / enjoys same priority and same associativity (Left to Right). Figure 1.12 shows for each operator which operand is unambiguous and which is not. Here since left operands for both operators are unambiguous Compiler is free to perform * or / operation as per its convenience.
since no matter which is performed earlier the result would be same.
Appendix A gives the associativity of all the operators available in C.
Popular posts
-
विश्वविद्यालय लानुपर्ने प्रवेश परीक्षाको उत्तरपुस्तिका विश्वविद्यालयका पदाधिकारी र कलेजका सञ्चालक मिलेर काठमाडौँको होटलमा जाँचेको उजुरी परे...
-
साथमा न श्रीमान् नै छन् न त छोराछोरी । रात बिताउने कुटी भए पनि बिहान बेलुकाको आहारा जुटाउने खेतबारी पनि छैन । विवाह गरेको वर्ष दिन नबित्दै र...
-
Make better use of the XP login screen . If your system contains more than one user account, or if you've set up XP to require logins,...
-
EPIDEMIOLOGY Lung cancer, broadly divided into small cell lung cancer (SCLC) and non-small cell lung cancer (NSCLC), is the leading cause ...
-
Dear Friends, This is the space provided by the google at free of cost, i thought why don't i use it to get some help for the users who ...
-
Introduction Drugs are the cornerstone of modern therapeutics. Nevertheless, it is well recognized among physicians and in the lay communi...
-
Small cell lung cancer (SCLC) represents approximately 15% to 25% of lung cancers. SCLC is characterized by its high growth fraction, rapi...
-
EPIDEMIOLOGY Lung cancer, broadly divided into small cell lung cancer (SCLC) and non-small cell lung cancer (NSCLC), is the leading cause ...
-
One of the toughest challenges facing any designer is the web page. There are perhaps millions of pages in the World Wide Web all jostling ...
-
N cell launched wi-fi router for multiple users Ncell have just yesterday launched the wi-fi routers, it was quite intresteting topic and sh...
Aug 1, 2011
Subscribe to:
Post Comments (Atom)


