Evaluate Postfix Expression using Stack C Program

By | October 5, 2016

Learn how to evaluate Postfix expression using Stack in C Programming Language. This C code for postfix evaluation takes in a postfix expression from the user and then evaluates it.

What is Postfix Expression?

In a postfix operation, he operators are placed after the operands. On scanning the expression from left to right, first the operands are recieved and then the operators.

Steps To Evaluate a Postfix Expression

  1. Scan the characters of the postfix string from left to right one by one.
    • If the character is an operand then push it on the stack.
    • If the character is an operator then pop two elements from the stack and apply the operator to these two characters. Now, push the result on the stack.
  2. After all the characters have been scanned, pop the remaining element of the stack and that is the value of the arithmetic postfix expression.

Example

Infix Expression: (3 + 4) * (2 / 2)

Postfix Expression: 34+22/*

Evaluation: 7

C Program To Evaluate Postfix Expression using Stack

Ouput

C Program To Evaluate Postfix Expression using Stack Data Structure

If you have any doubts or compilation errors in this c program for evaluation of postfix expression using stack in data structure, let us know about it in the comment section below.

Recommended Programs
C Program For Insertion Sort Algorithm
C Program To Convert Infix String into Postfix String
C Program For Evaluating a Prefix Expression
C Program To Convert Prefix String into Infix String
C Program To Convert Postfix String into Prefix String
C Program For Tower of Hanoi Algorithm
C Program To Convert Infix String To Prefix String
C Program To Convert Postfix String into Infix String
C Program To Generate Arithmetic Progression
C Program To Check Matching Parantheses in an Expression

2 thoughts on “Evaluate Postfix Expression using Stack C Program

  1. Vedant Mishra

    This is awesome. Just what i was looking for. Thanks codingalpha. Others have given first conversion of infix to postfix and then the evaluation. I was looking for direct evaluation of postfix expression. Nice work

    Reply
  2. viraj sardar

    Its a very good postfix evaluation program without using the function Isdigit, Though I wonder, Is it
    really necessary to use the IsEmpty() function? or can we just put that if checking in pop() function?

    Reply

Let's Discuss