M
Mukesh
Hello,
Please help in how the following program works(i.e behavior of if
statement inside switch default statement.) :
/**
* test.c - Test for switch construct.
*/
#include <stdio.h>
int main()
{
int i = 10 ;
printf("\n hello world\n");
switch (i) {
printf("\n In switch statement\n");
case 1:
printf("\n You entered: %d \n", i);
break;
case 2:
printf("\n You entered: %d \n", i);
break;
default :
if (9 == i) {
case 9:
printf("\n in case 9 entered value: %d\n", i);
break;
case 10:
printf("\n in case 10, entered value: %d\n", i);
break;
}
}
return 0;
}
Output:
++++++++
hello world
in case 10, entered value: 10
Please help in how the following program works(i.e behavior of if
statement inside switch default statement.) :
/**
* test.c - Test for switch construct.
*/
#include <stdio.h>
int main()
{
int i = 10 ;
printf("\n hello world\n");
switch (i) {
printf("\n In switch statement\n");
case 1:
printf("\n You entered: %d \n", i);
break;
case 2:
printf("\n You entered: %d \n", i);
break;
default :
if (9 == i) {
case 9:
printf("\n in case 9 entered value: %d\n", i);
break;
case 10:
printf("\n in case 10, entered value: %d\n", i);
break;
}
}
return 0;
}
Output:
++++++++
hello world
in case 10, entered value: 10