Practice mode Data Structures

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.