Skip to content
GATEiit

GATE CSE 2024 Session 1 Q33: Evaluate an expression under unusual precedence and associativity

Question

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

OperatorPrecedenceAssociativity
++HighestLeft
−-HighRight
∗*MediumRight
//LowRight

The value of the expression 3+1+5∗2/7+2−4−7−6/23 + 1 + 5 * 2 / 7 + 2 - 4 - 7 - 6 / 2 as per the above rules is __________

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 6 (official GATE 2024 final answer key)

Concept used: Parenthesise by precedence first, then group equal operators by associativity.

First step: Do the additions first: (3+1+5)=9(3 + 1 + 5) = 9 and (7+2)=9(7 + 2) = 9, giving 9∗2/9−4−7−6/29 * 2 / 9 - 4 - 7 - 6 / 2.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2024 Session 1 CS question paper and final answer key, organised by IISc Bangalore. Question paper · Answer key