WBJECA 2025 — Computer PYQ
WBJECA | Computer | 2025What is the value of the postfix expression 6 3 2 4 + − ∗ ?
Choose the correct answer:
- A.
-18
(Correct Answer) - B.
18
- C.
22
- D.
40
-18
Explanation
Explanation:
To evaluate a postfix expression, we scan the expression from left to right. When we encounter an operand, we push it onto the stack. When we encounter an operator, we pop the top two operands, perform the operation, and push the result back onto the stack.
Step-by-step evaluation:
Push 6: Stack = [6]
Push 3: Stack = [6,3]
Push 2: Stack = [6,3,2]
Push 4: Stack = [6,3,2,4]
Operator
+: Pop 4 and 2. Calculate 2+4=6. Push 6. Stack = [6,3,6]Operator
-: Pop 6 and 3. Calculate 3−6=−3. Push -3. Stack = [6,−3]Operator
*: Pop -3 and 6. Calculate 6⋅(−3)=−18. Push -18.
Final stack result is -18.
Mathematically, the evaluation steps can be represented as:
Initial expression=6 3 2 4 + − ∗
Final calculation=6⋅(3−(2+4))=6⋅(3−6)=6⋅(−3)=−18
