What is the value of the postfix expression 8 2 3 * − 4 2 / + ?
Correct answer A. 4
Explanation
Scan left to right with a stack. Push 8, 2, 3; * pops 3 and 2 and pushes 6; − pops 6 and 8 and pushes 8 − 6 = 2. Push 4 and 2; / gives 4 / 2 = 2. Finally + adds 2 and 2 to give 4. The order matters: the first popped value is the right operand, so 8 − 6, not 6 − 8.
Answer checked How we write and check questions
Discussion