# 3i Infotech Placement: Sample Questions 228 - 229 of 1245

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

## Question 228

### Question

MCQ▾

Output of the following program is

1. `main ()`
2. `{`
3. `    int i=0;`
4. `    for (i=0;i<20;i++)`
5. `    {`
6. `        switch (i)`
7. `        {`
8. `            case 0:i+=5;`
9. `            case 1:i+=2;`
10. `            case 5:i+=5;`
11. `            default:i+=4;`
12. `            break;`
13. `        }`
14. `        printf("%d,",i);`
15. `    }`
16. `}`

Choice (4)

a.

Syntax error

b.

0, 5, 9,13, 17

c.

16,21

d.

5, 9,13, 17

c.

### Explanation

• In the program
 int i = 0; Define the integer variable i = 0 for (i = 0; i < 20; i ++){ Apply the for loop switch (i){case 0: i += 5;case 1: i += 2;case 5: i += 5;default: i += 4;break;} Using switch caseCase 0 = i += 5Here i = 0Case 0 = 0 += 5Case 0 = 5In case 0 i = 5Case 1 = i += 2Here i = 5Case 1 = 5 += 2Case 1 = 7In case 1 i = 7Case 5 = i += 5Here i = 7Case 5 = 7 += 5Case 5 = 12In case 1 i = 12default = i += 4Here i = 12default = 12 += 4default = 16In default i = 16 printf ( “% d,” , i) ; Printf prints the “I” value and i = 16, so, print 16i value was increment in for loop and prints “2” 1So the answer is 16,21

Edit