GATE | GATE-CS-2015 (Set 3) | Question 65
Consider the following C program:
Attention reader! Don’t stop learning now. Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.
Learn all GATE CS concepts with Free Live Classes on our youtube channel.
The number of times printf statement is executed is __________.
Explanation: The following statement makes j = 2
j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
The following statement makes k = -1.
k -= --j;
There is one important thing to note in switch is, there is no break. Let count of printf statements be ‘count’
For i = 0, the value of i+k becomes -1, default block is executed, count = 1. For i = 1, the value of i+k becomes 0, default block is executed, count = 2. For i = 2, the value of i+k becomes 1, all blocks are executed as there is no break, count = 5 For i = 3, the value of i+k becomes 2, three blocks after case 1: are executed, count = 8 For i = 4, the value of i+k becomes 3, two blocks are executed, count = 10