Q51
Find the output of the following program. #include void main() int y=10; if(y++>9 && y++!=10 && y++>11) printf("%d", y); else printf("%d", y);
A.
11
B.
12
C.
13
AnswerD.
14
E.
Compilation error
Answer: Option C
Solution
Answer: Option C
Solution:
Here if Statement is true and if statement executes left to right. Since its AND operator so all the condition should be check until it finds any false statement.
Initially y = 10
In 1st condition: y++>9 which is true and y become 11 in next use.
In 2nd condition: y++!=10 which is also true and y become 12 in next use
In 3rd condition: y++>11 which is also true and y become 13 in next use
After that printf statement will execute and print y = 13