#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · STACK STEPS

Postfix Evaluator: Watch the Stack Solve Your Expression

Enter a postfix or prefix expression to see each push and pop and the final value.

  • 📚 Stack after every token
  • ↔️ Postfix and prefix
  • ⚠️ Clear error messages

How to use the Postfix Expression Evaluator

  1. 1. Pick the notationPostfix (RPN) or prefix (Polish).
  2. 2. Type the expressionNumbers and operators separated by spaces.
  3. 3. EvaluateSee every token, the action and the stack.

How stack evaluation works

In postfix notation the operator comes after its operands, so 3 4 + means 3 + 4. There are no brackets and no precedence rules to worry about, which is why calculators and compilers like it.

  1. Read the tokens left to right.
  2. A number is pushed onto the stack.
  3. An operator pops the top two values, applies itself (the lower value is the left operand) and pushes the result.
  4. At the end, exactly one value should be left: the answer.

Prefix notation puts the operator first: + 3 4. It's evaluated the same way but reading right to left, with the top of the stack as the left operand. Supported operators are + − * / % and ^ (power). If the stack runs out early or has values left over, you'll get a clear message saying what's wrong.

Worked example

Evaluate 5 1 2 + 4 * + 3 −:

  1. Push 5, push 1, push 2: [5, 1, 2].
  2. + pops 1 and 2 and pushes 3: [5, 3].
  3. Push 4: [5, 3, 4]. * pops 3 and 4 and pushes 12: [5, 12].
  4. + pops 5 and 12 and pushes 17: [17].
  5. Push 3, then − pops 17 and 3 and pushes 14: [14].

The answer is 14, the same as the infix expression 5 + (1 + 2) × 4 − 3. The equivalent prefix expression − + 5 * + 1 2 4 3 also gives 14; switch the notation to check. To turn an infix expression into postfix in the first place, use the Infix to Postfix converter.

Frequently asked questions

Do I need spaces between tokens?

Yes, so multi-digit numbers like 12 are read correctly. A single string of one-digit numbers and operators, like 23+4*, also works.

Which operand comes first for subtraction?

In postfix, the value pushed earlier is on the left: 10 3 − is 10 − 3 = 7.

Are decimals and negative numbers allowed?

Yes, like 2.5 or -4, written as separate tokens.

Is the postfix expression evaluator free to use?

Yes, the postfix expression evaluator is free and costs nothing. Your first evaluation shows a short form for your name and WhatsApp number one time; once that's done, this tool and every other Uncodemy tool open with no form.

More free tools

See all free tools