Switch Case in C Exercise I


Ques 1 Switch Case


What is the output of the following code?
int main()
{
    int k=0;
    k=k+2;
    switch(k)
    {
        case 0:printf("case 0");
        case 1:printf("case 1");
        case 2:printf("case 2");break;
        default: printf("SmallCode");
    }
    return 0;
}

  a) case 0 case 1
  b) case 1
  c) case 2
  d) SmallCode


c is the correct option




Ques 2 Switch Case


What is the output of the following code?
int main()
{
    int k=0;
    k=k+2;
    switch(k)
    {
        case 0:printf("case 0");
        case 1:printf("case 1");break;
        case 2:printf("case 2");continue;
        default: printf("SmallCode");
    }
    return 0;
}

  a) case 0
  b) case 1
  c) case 2
  d) compilation error


c is the correct option




Ques 3 Switch Case


What is the output of the following code?
int main()
{
    float k=0;
    switch(k)
    {
        case 0:printf("case 0");
        case 1:printf("case 1");break;
        case 2:printf("case 2");break;
        default: printf("SmallCode");
    }
    return 0;
}

  a) case 0
  b) case 1
  c) case 2
  d) SmallCode


d is the correct option