|
|
. |
|
C
For Swimmers : Mastering C step-by-step |
|
|
|
Notations
|
|
Types of
Notations :
- Infix notation
- Prefix notation
- Postfix notation
Consider the sum of A and B. We think of applying the operator “+” to the operands A and B to write the sum as A+B. This particular representation is called
Infix notation. There are two alternate notations for expressing the sum of A and B using the symbols A, B and +. These are
+ A B Prefix notation
A B + Postfix notation
The prefixes “pre-“, “post-“ and “in-“ refer to the relative position of the operator with respect to the two operands.
In Prefix notation the operator
precede the two operands,
In Postfix notation the operator
follows the two operands and
In Infix notation the operator is
between the two operands.
The evaluation of the expression A + B * C, as written in standard infix notation, requires knowledge of which of the two operations, + or *, is to be performed first. In the case of + and *, we “know” that multiplication is to be done before addition (in the absence of
parenthesis to the contrary). Thus A+B*C is interpreted as A + ( B * C ) unless otherwise specified. We say that multiplication takes precedence over addition. Suppose that we want to rewrite A + B * C in postfix. Applying the rules of precedence, we first convert the portion of the expression that is evaluated first, namely the multiplication. By doing this conversion in stages, we obtain :
A + ( B * C ) Paranthesis for emphasis
A + ( BC* ) Convert the multiplication
A ( BC* ) + Convert the addition
ABC*+ Postfix form
The only rules to remember during the conversion process are that
operations with highest precedence are converted first
and that after a portion of the expression has been converted to postfix, it is to be treated as a single operand. Consider the same example with the precedence of operators reversed by the deliberate insertion of paranthesis.
( A + B ) * C Infix form
( AB+ ) * C Convert the addition
( AB+ ) C * Convert the multiplication
AB+C* Postfix form
In the above example the addition is converted before the multiplication because of the
parenthesis. In going from ( A + B ) * C to ( AB+ ) * C, A and B are the operands and + is the operator. In going from ( AB+ ) * C to ( AB+ ) C *, ( AB+ ) and C are the operands and * is the operator. The rules for converting from infix to postfix are simple, providing that you know the order of precedence.
|
|
|
You are
Visitor No. 
Sign
my Guestbook
View
my Guestbook
Thanks for using C For Swimmers.
Regarding this material, you can send Bug Reports,
Suggestions, Comments, etc. to
nandakishorkn@rediffmail.com
|
|
|
Note: All
logos or trademarks are related to their respective owners.
Although every
precaution has been taken, the designer(s) owe no responsibility
for malicious errors.
No liability assumed
for damages resulting from the use of the available information.
|