367 views

2 Answers

0 votes
0 votes

There is no break inside switch. So all cases will execute.

We enter the switch with i=0 and come out with i=16. 

Print=> 16

Now second iteration will begin. 16<20 evaluates to true. So i becomes 17. 

This time, only default case will execute. So i = 17+4= 21

Print=> 21

0 votes
0 votes
1.First of all expression inside switch will be executed, i.g, switch(<expression>).

2. Now the value of this expression will be matched with 'case' blocks. If no match then 'default' block will be chosen.

3. If we will not use 'break' statement then the following 'case' blocks or 'default' block will also get executed untill it encounters first 'break' or end of the 'switch' block.

Now in this question:

Initially, i=0.

Case 0, will execute first. It will make i=5. Since there is no 'break' statement, so the following cases will also get executed, making 'i' value to 7,  12 and at the end 16(default case). So in 1st iteration 16 will get printed.

Now in 'for' loop, i= 17, only deafult case will execute , now i=21. So 21 will get printed.

It will terminate the 'for' loop.

I think this is the main concept !! correct if I am wrong.

Related questions

1 votes
1 votes
2 answers
1
Sazia Tabassum asked Oct 14, 2022
593 views
The return value of ace(4) is int ace(int a) { int x=1; static int k=1; if(a==1) return x; for(;k<a;++k) x=x+ace(k)*ace(a-k); return x; }A.15B.4C.10D.Error
0 votes
0 votes
3 answers
2
ramakrushna asked Dec 23, 2021
729 views
What should be the ans. Isn’t the Function initialization should be outside main function? They are given inside main. If declaration would be outside main then ans sho...
1 votes
1 votes
0 answers
3
srestha asked Mar 6, 2019
780 views
void find(int x){ static int i=10,y=0; y=y+i; for(i;i>0;i=i-10){ if(x!=0) find(x-1); else{ printf("%d",y); } } }What will be output printed for find(4)?
0 votes
0 votes
0 answers
4
register_user_19 asked Jan 10, 2019
440 views
What is the output of the following code ?void f(int a, int b){printf(“%d”,a+b);}void main(){f((2,3),4);}675None of these