# Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 68 - 69 of 354

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

## Question 68

C & C Plus Plus

### 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

## Question 69

C & C Plus Plus
Edit

### Describe in Detail

Essay▾

Find the output of the following program

1. `class base`
2. `{`
3. `    public:`
4. `    int bval;`
5. `    base()`
6. `    {`
7. `        bval=0;`
8. `    }`
9. `};`
10. `class deri:`
11. `public base`
12. `{`
13. `    public:`
14. `    int dval;`
15. `    deri()`
16. `    {`
17. `        dval=1;`
18. `    }`
19. `};`
20. `void SomeFunc(base ⚹arr, int size)`
21. `{`
22. `    for(int i=0; i cout <bval;cout << endl;)`
23. `}`
24. `int main()`
25. `{`
26. `    base BaseArr[5];`
27. `    SomeFunc(BaseArr,5);`
28. `    deri DeriArr[5];`
29. `    SomeFunc(DeriArr,5);`
30. `}`

### Explanation

• 00000

01010

• In the program
 `class base``{``    public:``    int bval;``    base()``    {``        bval=0;``    }``};` Define the base classDefine the integer variable bvalHere bval = 0 `class deri:``public base``{``    public:``    int dval;``    deri()``    {``        dval=1;``    }``};` Define the deri classDefine the integer variable dvalHere dval = 1 `void SomeFunc(base ⚹arr, int size)``{``    for(int i=0; i cout = sizeof (int) + sizeof (int) ) .

Developed by: