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.
- Re: [c-prog] please help prityanka biswas
- RE: [c-prog] please help KANNAN RAMALINGAM
- RE: [c-prog] please help prityanka biswas
- [c-prog] allocate - initialize - assign Robert Ryan
- Re: [c-prog] allocate - initialize - assign Jacob Lund Fisker
- Re: [c-prog] allocate - initialize - as... Robert Ryan
- Re: [c-prog] allocate - initialize... Robert Ryan
- Re: [c-prog] allocate - initia... Robert Ryan
- Re: [c-prog] allocate - initialize... Thomas Hruska
- Re: [c-prog] allocate - initialize - assign Wang Jun
- Re: [c-prog] solution fromme
- [c-prog] Please Help Chris
- Re: [c-prog] Please Help Jim Dougherty
- RE: [c-prog] Please Help Chris Varner
- Re: [c-prog] Please Help Steve Searle
- Re: [c-prog] Please Help Jim Dougherty
- RE: [c-prog] Please Help Chris Varner
- Re: [c-prog] Please Help Jim Dougherty
- [c-prog] please help ali5763237
- Re: [c-prog] please help John Gaughan
