Unit - 1 CP (Lecture 7)
Unit - 1 CP (Lecture 7)
Unit - 1 CP (Lecture 7)
1
Topics to be Covered
• Expressions
• Evaluation of expressions
• Type conversion
• precedence
• associatively
axb–c a*b–c
(m + n) (x + y) (m + n) * (x + y)
(ab / c) a*b/c
(x / y) + c x/y+c
6
Precedence in Arithmetic Operators
• An arithmetic expression without parenthesis will be evaluated from left to right using
the rules of precedence of operators. There are two distinct priority levels of arithmetic
operators in C.
High priority * / %
Low priority + -
7
Rules for evaluation of expression
8
Type Conversions
9
Implicit Type Conversion
• C automatically converts any intermediate values to the proper type so that the
expression can be evaluated without loosing any significance. This automatic type
conversion is know as implicit type conversion
• During evaluation it adheres to very strict rules and type conversion. If the operands
are of different types the lower type is automatically converted to the higher type
before the operation proceeds. The result is of higher type.
• Type conversions can be implicit which is performed by the compiler automatically, or
it can be specified explicitly through the use of the cast operator.
10
Implicit Conversion
(a) An arithmetic operation between an integer and integer always yields an integer
result.
(b) An operation between a real and real always yields a real result.
(c) An operation between an integer and real always yields a real result. In this operation
the integer is first promoted to a real and then the operation is performed. Hence the
result is real.
13
Operator Precedence And Associativity
• [1] https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQ1BaB25ZbSO5Oq2uvpkrYA8XxZWI95l
• colqeG8ONh4ZX0J-_D&usqp=CAU
• [2] https://media.geeksforgeeks.org/wp-content/uploads /20190801163131/What-is-an-Expression_-3.jpg
• [3] https://media.geeksforgeeks.org/wp-content/uploads/20190801154515/Types-of-Expressions.jpg
• [4] https://www.thecrazyprogrammer.com/type-conversion-precedence-and-associativity-of-operators-in-
c.html
• [5] Ref. -https://data-flair.training/blogs/wp-content/uploads/sites/2/2019/06/Implicit-Type-Conversion-.jpg
17
Reference Books
• T1 E. Balaguruswamy, Programming in ANSI, McGraw-Hill Education,
• https://bookmart.online/shop/programming-in-ansi-c-8-e-balagurusamy-second-hand-book/?ut
m_source=Google%20Shopping&utm_campaign=test&utm_medium=cpc&utm_term=498
18
THANK YOU
For queries
Email:[email protected]