edited by
3,166 views
3 votes
3 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 ________.

 

edited by

1 Answer

4 votes
4 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

1.6k
views
1 answers
0 votes
Arjun asked Feb 16
1,584 views
Let $G=(V, \Sigma, S, P)$ be a context-free grammar in Chomsky Normal Form with $\Sigma=\{a, b, c\}$ and $V$ containing $10$ variable symbols including the start symbol $...
10.4k
views
4 answers
35 votes
Sandeep Singh asked Feb 12, 2016
10,401 views
The attribute of three arithmetic operators in some programming language are given below.$$\begin{array}{|c|l|}\hline \textbf{OPERATOR} & \textbf{PRECEDENCE} & \textbf{...
2.4k
views
1 answers
1 votes
Arjun asked Feb 16
2,414 views
Which of the following is/are Bottom-Up Parser(s)?Shift-reduce ParserPredictive ParserLL$(1)$ Parser LR Parser
2.2k
views
2 answers
0 votes
Arjun asked Feb 16
2,216 views
​Consider the following syntax-directed definition $\text{(SDD)}$.$S \rightarrow D H T U$$ \left\{S.v a l = D.val + H.val + T.val + U.val\right\};$$D \rightarrow ^{"} \...