Question

The result evaluating the postfix expression

105+606/∗8−10 \quad 5 \quad + \quad 60 \quad 6 \quad / \quad * \quad 8 \quad -

is

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2015 answer key

Solution

Evaluate the postfix expression step-by-step using an operand stack.

The postfix expression is: 10 5 + 60 6 / * 8 -.
We scan tokens from left to right, pushing numbers onto the stack and popping operands when an operator is encountered:

  1. 10: Push onto stack   ⟹  [10]\implies [10]
  2. 5: Push onto stack   ⟹  [10,5]\implies [10, 5]
  3. +: Pop 55 and 1010, compute 10+5=1510 + 5 = 15, push 15  ⟹  [15]15 \implies [15]
  4. 60: Push onto stack   ⟹  [15,60]\implies [15, 60]
  5. 6: Push onto stack   ⟹  [15,60,6]\implies [15, 60, 6]
  6. /: Pop 66 and 6060, compute 60/6=1060 / 6 = 10, push 10  ⟹  [15,10]10 \implies [15, 10]
  7. *: Pop 1010 and 1515, compute 15×10=15015 \times 10 = 150, push 150  ⟹  [150]150 \implies [150]
  8. 8: Push onto stack   ⟹  [150,8]\implies [150, 8]
  9. -: Pop 88 and 150150, compute 150−8=142150 - 8 = 142, push 142  ⟹  [142]142 \implies [142]

The final result on top of the stack is 142 (Option C).

Final answer

C

Common trap

Reversing the operand order during division or subtraction (e.g., 6 / 60 or 8 - 150).

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2015 Computer Science and Information Technology (CS) Session 3
Question
22 of 65, printed as CS Q.12
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.