Practice mode Data Structures

What is the value of the postfix expression 9 3 / 2 ^ 1 + , where ^ means exponentiation?

Correct answer D. 10

Explanation

Push 9 and 3; / gives 9 / 3 = 3. Push 2; ^ gives 3 squared = 9. Push 1; + gives 9 + 1 = 10. Postfix needs no brackets or precedence rules because each operator applies immediately to the top two stack values, with the lower one as the left operand. Getting 19 would mean the operators were applied in the wrong order.

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.