The previous post of the blog about c programming deals with concept of mathematical conversions.

The priority or precedence in which the operations in an arithmetic statement are performed is called the hierarchy of operations. The hierarchy of commonly used operators is shown in Figure .

General rules :

1 . Within parentheses the same hierarchy as mentioned in Figure 1.11 is operative. Also, if there are more than one set of parentheses, the operations within the innermost parentheses would be performed first, followed by the operations within the second innermost pair and so on.

2 . We must always remember to use pairs of parentheses. A careless imbalance of the right and left parentheses is a common error. Best way to avoid this error is to type ( ) and then type an expression inside it.

Examples :

1 . Determine the hierarchy of operations and evaluate the following expression:

i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8

This can be done step by step as shown.

i = 6 / 4 + 4 / 4 + 8 - 2 + 5 / 8 operation: *
i = 1 + 4 / 4 + 8 - 2 + 5 / 8 operation: /
i = 1 + 1+ 8 - 2 + 5 / 8 operation: /
i = 1 + 1 + 8 - 2 + 0 operation: /
i = 2 + 8 - 2 + 0 operation: +
i = 10 - 2 + 0 operation: +
i = 8 + 0 operation : -
i = 8 operation: +

Note that 6 / 4 gives 1 and not 1.5. This so happens because 6 and 4 both are integers and therefore would evaluate to only an integer constant. Similarly 5 / 8 evaluates to zero, since 5 and 8 are integer constants and hence must return an integer value.

2 . Determine the hierarchy of operations and evaluate the following expression:

k = 3 / 2 * 4 + 3 / 8 + 3

Stepwise evaluation of this expression is shown below:

k = 3 / 2 * 4 + 3 / 8 + 3
k = 1 * 4 + 3 / 8 + 3 operation: /
k = 4 + 3 / 8 + 3 operation: *
k = 4 + 0 + 3 operation: /
k = 4 + 3 operation: +
k = 7 operation: +

All operators in C are ranked according to their precedence.

conversion of a general arithmetic statement to a C statement :

Here is the list of some simple examples which will give a outline about the conversion .


Related posts :

Instructions to write c programs part one and two.
Compilation and execution of a c program
Rules to follow to write a c program part one and two

You can browse COMPLETE C PROGRAMMING COURSE here.

Thank you for visiting PROGRAMMING BLOG. If you liked the post, please subscribe to my blog via email or RSS FEED.You can contact me here for any specific feed back .

I am requesting your's feedback.

Are you satisfied with the present post ?
Have you got sufficient information you are looking for here at this post and on the blog ?
What else is missing and what topics have to be incorporated in this blog ?
Let me know so that i can make it better .


COMMENT HERE and thank you for sparing your valuable time.

I request you to share this page on your favorite social book marking site with the below link.

Share/Save/Bookmark

0 comments

Post a Comment