For handling the expressions the operators are used. C support following set of operators
Expressions using Operators
AU:
May-19, Dec.-19, Marks 13
For
handling the expressions the operators are used. C support following set of
operators -
Conditional
operator :
The
conditional operator is? The syntax of using conditional operator is
For
example A
a
> b?true:false
This
means if a is greater than b, if yes then the value will be true otherwise it
will be false.
Precedence
of Operators
Precedence
means the priority of certain operation.
1.
In case there is a tie between operations of same priority preference is given
to the operator which occurs first.
2.
Within a paranthesis, the same hierarchy is operative. If there are more than
one set of paranthesis inner most parantheses will be performed first, followed
by operations within second.
e.g.
a = 3/2*4+3/8+3
Stepwise
evaluation to
a
= 3/3*4+3/8+3 operation /
=
1*4+3/8+3 operation
=
4+3/8+30 operation
=
4+0+3 operation +
=
4+3 operation +
=
7
Ex.
1.5.1 Determine the output of the following "C" statements: Assume a
= 13, b = 25 and c = 5.
i)
z = a Λ
b ii) x = ++ab iii) y = b++ + C
iv)
x = c > b ?1 : 0,
Sol.
: i)
z = 20 as it is logical bit wise EX-OR operation
The
truth table for EX-OR operation is as shown below
As
++a is a pre increment operator the value of a is incremented by one before the
expression gets evaluated.
iii)
30 since y = b++c = 25+ 5
As
b++ is a post increment operator, after expression gets incremented the value
of b becomes 26.
iv)
0
The
meaning of this expression is if c> b is true then print 1 otherwise 0. As
value of c is less than b the output will be 0.
Review Questions
1. List all the operators in C with an example for each. AU:
May-19, Marks 7 oals neo insmeisje
2. Describe the various operators in C with examples and the
associativity. AU: Dec.-19, Marks 13
C Programming and Data Structures: Unit I: C Programming Fundamentals : Tag: : C Programming - Expressions using Operators
C Programming and Data Structures
CS3353 3rd Semester EEE, ECE Dept | 2021 Regulation | 3rd Semester EEE Dept 2021 Regulation