Vidyalelo
C Programming · Q42

Operators and Expressions

Programming · C Programming · question 42

Q42

What number will z in the sample code given below? int z, x=5, y= -10, a=4, b=2; z = x++ - --y*b/a;

A.
5
B.
6
C.
9
D.
10
Answer
E.
11

Answer: Option D

Solution

Answer: Option D
Solution:

C Operator Precedence Table
According to precedence table execution of the given operators are as follows:
1. x++(Postfix operator) i.e x will become 5
2. y--(Prefix operator) i.e y will become -11
3. * and / have same priority so they will be executed according to their associativity i.e left to right. So, *(Multiplication) will execute first and then /(division).
4. -(Subtraction)

So the complete expression would be
5 - (-11)*2/4 = 5 - (-22)/4 = 5 - (-5) = 5 + 5 = 10.