Question
The result evaluating the postfix expression
is
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:
10: Push onto stack5: Push onto stack+: Pop and , compute , push60: Push onto stack6: Push onto stack/: Pop and , compute , push*: Pop and , compute , push8: Push onto stack-: Pop and , compute , push
The final result on top of the stack is 142 (Option C).
C
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.