Vidyalelo
C Programming · Q39

Control Structures

Programming · C Programming · question 39

Q39

What will be the output of the given program? #include void main() int value1, value2=100, num=100; if(value1=value2%5) num=5; printf("%d %d %d", num, value1, value2);

A.
100 100 100
B.
5 0 20
C.
5 0 100
D.
100 0 100
Answer
E.
100 5 100

Answer: Option D

Solution

Answer: Option D
Solution:

Expression value2%5 is equal to 0 and this value assigned to value1.
Therefore if condition reduces to if(0) so it fails.
Therefore body of if will not be executed i.e num = 5 will not be assigned.
So at printf num = 100 , value1 = 0 and value2 = 100.