in Compiler Design edited by
1,990 views
2 votes
2 votes

Consider the operator precedence and associativity rules for the integer arithmetic operators given in the table below.

Operator PrecedenceAssociativity
+Highest Left
-HighRight
*MediumRight
/ LowRight

The value of the expression $3+1+5 * 2 / 7+2-4-7-6 / 2$ as per the above rules is ________.

in Compiler Design edited by
by
2.0k views

1 Answer

2 votes
2 votes

The given expression is evaluated as follows:

$\implies 3+1+5*2/7+2-4-7-6/2$

$\implies(3+1)+5*2/7+2-4-7-6/2$

$\implies(4+5)*2/7+2-4-7-6/2$

$\implies9*2/(7+2)-4-7-6/2$

$\implies9*2/9-4-7-6/2$

$\implies9*2/9-4-(7-6)/2$

$\implies9*2/9-(4-1)/2$

$\implies9*2/(9-3)/2$

$\implies9*2/6/2$

$\implies(9*2)/6/2$

$\implies18/6/2$

$\implies18/(6/2)$

$\implies18/3=6$

Similar kind of questions  asked in GATE CSE 2016 Set 1 | Question: 45

edited by
Answer:

Related questions