Associativity-and-Precedence

Question 1

The attributes of three arithmetic operators in some programming language are given below.

Operator      Precedence     Associativity     Arity 
   +             High            Left          Binary
   −            Medium           Right         Binary
   ∗             Low             Left          Binary

The value of the expression 2 – 5 + 1 – 7 * 3 in this language is __________.

A
9
B
10
C
11
D
12
Question 1 Explanation: 
+ has highest precedence, so it will be evaluated first.
2 − 5 + 1 − 7 * 3 = 2 − (5 + 1) − 7 * 3 = 2 − 6 − 7 * 3
Now, − has more precedence than *, so sub will be evaluated before * and – has right associative so (6 − 7) will b
There is 1 question to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access