titli_juit wrote:
> 
>      #include<stdio.h>
> int main()
>         {
>            int i=0;
>          for(i=0;i<20;i++)
>             {
>                        switch(i){
>                case 0:i+=5;
>                case 1:i+=2;
>                case 5:i+=5;
>                default : i+=4;
>                                  break;}
>                
>                printf("%d,",i);
>                }    
>          
> return 0;
> }
> 
> the output is 16,21
> 
> can you please explain how am i getting this output? 
> 
> 
> 


Since there is no break statement provided for each case.
first iteration
i.e for i=o:
 the value of i when it comes out of the break statement will be 
i=(((i+5)+2)+5)+4 . so the final value is 16. thus prints 16.

now i is incremented in the for statement to 17. and 17<20. so for loop
continues once again.

we have i=17, switch chooses default, so nwo i+=4 leads i=17=4=21
prints 21.

now i++ in for statement makes i=21. and 21<20 is false. so for loop breaks.


still if u've not understood mailto: [EMAIL PROTECTED]


-- 
View this message in context: 
http://www.nabble.com/please-help-tf4795728.html#a13776496
Sent from the C-prog mailing list archive at Nabble.com.

Reply via email to