1. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        unsigned char c=280;
        switch(c){
            printf("Start\t");
            case 280:printf("David Beckham\t");
            case 24: printf("Ronaldinho\t");
            default:  printf("Ronaldo\t");
            printf("End");
        }
    }
    Choose all that apply:

    A
    Start David Beckham Ronaldinho Ronaldo End

    B
    Start David Beckham Ronaldinho Ronaldo

    C
    Start Ronaldinho Ronaldo End

    D
    Ronaldinho Ronaldo End

    E
    Compilation error

    Note: 280 is beyond the range of unsigned char. Its corresponding cyclic value is: 24 In c switch case statement program control always move from the case which satisfy the switch condition and end with either break keyword, terminating} or any null character which will come first.
    1. Report
  2. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    #define TRUE 1
    void main(){
        switch(TRUE){
            printf("cquestionbank.blogspot.com");
         }  
    }
    Choose all that apply:

    A
    cquestionbank.blogspot.com

    B
    It will print nothing

    C
    Runtime error

    D
    Compilation error

    E
    None

    Note: In c it is possible a switch case statement without any case but it is meaning less.
    1. Report
  3. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         static int i;
         int j=1;
         int arr[5]={1,2,3,4};
         switch(arr[j]){
            case 1: i++;break;
            case 2: i+=2;j=3;continue;
            case 3: i%=2;j=4;continue;
            default: --i;
         }
         printf("%d",i);  
    }
    Choose all that apply:

    A
    0

    B
    1

    C
    2

    D
    Compilation error

    E
    None

    Note: We cannot use continue keyword in switch case. It is part loop.
    1. Report
  4. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         static int i;
         int j;
         for(j=0;j<=5;j+=2)
         switch(j){
            case 1: i++;break;
            case 2: i+=2;
            case 4: i%=2;j=-1;continue;
            default: --i;continue;
         }
         printf("%d",i); 
    }
    Choose all that apply:

    A
    0

    B
    1

    C
    2

    D
    Compilation error

    E
    None

    Note: In first iteration of for loop: j = 0 So, control will come to default, i = -1 Due to continue keyword program control will move to beginning of for loop In second iteration of for loop: j =2 So, control will come to case 2, i+=2 i = i+2 = -1 +2 =1 Then come to case 4, i%=2 i = i%2 = 1%2 = 1 j= -1 Due to continue keyword program control will move to beginning of for loop In third iteration of for loop: j = -1 +2 =1 So, control will come to case 1 i = 2 In the fourth iteration of for loop: j = 1+ 2 =3 So, control will come to default, so i = 1 In the fifth iteration of for loop: j = 3 + 2 =5 So, control will come to default, so i = 0 In the sixth iteration of for loop: j = 5 + 2 =7 Since loop condition is false. So control will come out of the for loop.
    1. Report
  5. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         int x=3;
         while(1){
            switch(x){
                 case 5/2: x+=x+++x;
                 case 3%4: x+=x---x;continue;
                 case 3>=3: x+=!!!x;break;
                 case 5&&0:x+=~~~x;continue;
                 default: x+=-x--;
            }
            break;
         }
         printf("%d",x);   
    }
    Choose all that apply:

    A
    3

    B
    -1

    C
    5

    D
    Compilation error

    E
    None

    Note: Not available
    1. Report
  6. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         char *str="cquestionbank.blogspot.com";
         int a=2;
         switch('A'){
            case 97:
                 switch(97){
                     default: str+=1;
                 }
            case 65:
                 switch(97){
                     case 'A':str+=2;
                         case 'a':str+=4;
             }
            default:
             for(;a;a--)
                 str+=8;
         }
         printf("%s",str); 
    }
    Choose all that apply:

    A
    cquestionbank.blogspot.com

    B
    blogspot.com

    C
    com

    D
    Compilation error

    E
    None

    Note: ASCII value of the character constant 'A' is 65 and 'a' is 97. Nesting of switch case is possible in c.
    1. Report
  7. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         switch(2){
            case 1L:printf("No");
            case 2L:printf("%s","I");
                 goto Love;
            case 3L:printf("Please");
            case 4L:Love:printf("Hi");
         } 
    }
    Choose all that apply:

    A
    I

    B
    IPleaseHi

    C
    IHi

    D
    Compilation error

    E
    None

    Note: It is possible to write label of goto statement in the case of switch case statement.
    1. Report
  8. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         int a=5;
         a=a>=4;
         switch(2){
            case 0:int a=8;
            case 1:int a=10;
            case 2:++a;
            case 3:printf("%d",a);
         }
    }
    Choose all that apply:

    A
    8

    B
    11

    C
    10

    D
    Compilation error

    E
    None

    Note: We can not declare any variable in any case of switch case statement.
    1. Report
  9. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         int a=3,b=2;
         a=a==b==0;
         switch(1){
            a=a+10;
         }
         sizeof(a++);
         printf("%d",a); 
    }
    Choose all that apply:

    A
    10

    B
    11

    C
    13

    D
    1

    E
    Compilation error

    Note: Consider on the expression: a=a==b==0; a=(a==b)==0; //Since associate is right to left a =(3==2)==0 a=0==0 a=1 switch case will not affect the value of variable a. Also sizeof operator doesn't affect the value of the any variable
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd