Assignment - 2 Expression Evaluation
Assignment - 2 Expression Evaluation
Branch : I B.Tech-CSE
Topic : Operator evaluation in. C
Assignment : 02
Expression Evaluation
• Precedence specifies the order of evaluation of operators in an expression.
• If pusing precedence of two operators is same then use associativity of the operators, which
specifies the order of evaluation (i.e., from left to right or right to left)
Note: See Q.No 1 & 2 for writing the explaination for the remaining questions.
Q.No Assume the value Find the value ‘a’ after Explaination
the executing the
following expression
1(ex) b=2,c=3,d=4 a=b*c +d The precedence of * is greater than + .
so a = 2*3+4
= 6+4
= 10
2(ex.) b =3, c=8, d=3 a=b*c/d The precdence of * and / is same. So the
associativity is left to right.
So a = 3*8/3
= 24/3
=8
3 b=2,c=3,d=4 a=d / b % c
5 b=9,c=3,d=2 a= b/c/d
6 b=6, c=12, a = b+c > d- c
d=15.
7 b=2 and c=3 a = b+1 > c
8 b=2,c=3,d=4, a = b > c && e < d.
e=5.
9 b= 1, c = 2 a=b++ + c++
10 b= 1, c = 2 a=++b + c++
11 b= 1, c = 2 =b++ + ++c
12 b= 1, c = 2 =++b + c++
13 b=-1, c=1 a = b++ || b >c
14 b=-1, c=1 a = ++b && b >c
15 a=2, b=3, c =3 a= b>c ? a++ : --a