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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.