the cases are simple lables they have nothing to do with the flow of
program.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Fri, Jun 29, 2012 at 3:14 PM, adarsh kumar <algog...@gmail.com> wrote:

> Doubt, very trivial though:
> #include<stdio.h>
> int main()
> {
>     int x=3;
>     switch(x)
>     {
>      case 1:
>             x=1;
>             break;
>      case 2:
>             x=2;
>             break;
>      case 3:
>             x=3;
>             break;
>      default:
>              x=0;
>              break;
>      case 4:
>             x=4;
>             break;
>     }
> printf("%d",x)
>     return 0;
> }
> gives an output of 3. But,
> #include<stdio.h>
> using namespace std;
> int main()
> {
>     int x=3;
>     switch(x)
>     {
>      case 1:
>             x=1;
>      case 2:
>             x=2;
>      case 3:
>             x=3;
>      default:
>              x=0;
>      case 4:
>             x=4;
>     }
>    printf("%d",x);
>     getch();
>     return 0;
> }
> gives an output of 4.
> My doubt is, in spite of the missing break statements in the second case,
> how will it enter case 4, as it should check if x=4 before doing that,
> which is not true.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to