Vidyalelo
C Programming · Q37

Control Structures

Programming · C Programming · question 37

Q37

What will be the output of the given program? #include void main() int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);

A.
12 7
B.
5 6
C.
6 6
Answer
D.
6 7
E.
11 6

Answer: Option C

Solution

Answer: Option C
Solution:

Here if condition evaluates to true as a non-zero value i.e 5 is assigned to a.
So the value of a = 5 and after increment value of b = 6.
In printf statement due to pre-increment of a value of a printed will be 6 and due to post-increment of b value of b printed will be 6 and not 7.