Expressions

 What is an Expression?

In any programming language, if we want to perform any calculation or to frame a condition etc., we use a set of symbols to perform the task. These set of symbols makes an expression.

An expression can be defined as follows...

An expression is a collection of operators and operands that represents a specific value.

Operator is a symbol which performs a particular task like arithmetic operation or logical operation or conditional operation etc.,

Operands are the values on which the operators can perform the task. Here operand can be a direct value or variable or address of memory location.

 

Expression Types

Based on the operator position, expressions are divided into THREE types. They are as follows...

  1. Infix Expression
  2. Postfix Expression
  3. Prefix Expression
Infix Expression

In infix expression, operator is used in between the operands.

The general structure of an Infix expression is as follows...

                            Operand1 Operator Operand2

 Example
 
Postfix Expression
 
The expression in which the operator is used after operands is called postfix expression.
The postfix expression has the following general structure.
 
Operand1 Operand2 Operator  
 

Prefix Expression

In prefix expression, operator is used before operands. We can say that "Operands follows the Operator".

The general structure of Prefix expression is as follows...

                            Operator Operand1 Operand2

Example
 

 
Every expression can be represented using all the above three different types of expressions. And we can convert an expression from one form to another form like Infix to Postfix, Infix to Prefix, Prefix to Postfix and vice versa.

No comments:

Post a Comment