1. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         int movie=1;
         switch(movie<<2+movie){
            default:printf("3 Idiots");
            case 4: printf(" Ghajini");
            case 5: printf(" Krrish");
            case 8: printf(" Race");
         } 
    }
    Choose all that apply:

    A
    3 Idiots Ghajini Krrish Race

    B
    Race

    C
    Krrish

    D
    Ghajini Krrish Race

    E
    Compilation error

    Note: We can write case statement in any order including the default case. That default case may be first case, last case or in between the any case in the switch case statement.
    1. Report
  2. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    #define L 10
    void main(){
         auto money=10;
         switch(money,money*2){
            case L:  printf("Willian");
                      break;
            case L*2:printf("Warren");
                      break;
            case L*3:printf("Carlos");
                      break;
            default: printf("Lawrence");
            case L*4:printf("Inqvar");
                      break;
         }  
    }
    Choose all that apply:

    A
    Willian

    B
    Warren

    C
    Lawrence Inqvar

    D
    Compilation error: Misplaced default

    E
    None

    Note: In c comma is also operator which enjoy least precedence. So if x = (a , b); Then x = b Note: Case expression can be macro constant.
    1. Report
  3. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         int const X=0;
         switch(5/4/3){
            case X:  printf("Clinton");
                      break;
            case X+1:printf("Gandhi");
                      break;
            case X+2:printf("Gates");
                      break;
            default: printf("Brown");
         } 
    }
    Choose all that apply:

    A
    Clinton

    B
    Gandhi

    C
    Gates

    D
    Brown

    E
    Compilation error

    Note: Case expression cannot be constant variable.
    1. Report
  4. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    enum actor{
        SeanPenn=5,
        AlPacino=-2,
        GaryOldman,
        EdNorton
    };
    void main(){
         enum actor a=0;
         switch(a){
            case SeanPenn:  printf("Kevin Spacey");
                             break;
            case AlPacino:  printf("Paul Giamatti");
                             break;
            case GaryOldman:printf("Donald Shuterland");
                             break;
            case EdNorton:  printf("Johnny Depp");
         }  
    }
    Choose all that apply:

    A
    Kevin Spacey

    B
    Paul Giamatti

    C
    Donald Shuterland

    D
    Johnny Depp

    E
    Compilation error

    Note: Default value of enum constant GaryOldman = -2 +1 = -1 And default value of enum constant EdNorton = -1 + 1 = 0 Note: Case expression can be enum constant.
    1. Report
  5. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         switch(*(1+"AB" "CD"+1)){
            case 'A':printf("Pulp Fiction");
                      break;
            case 'B':printf("12 Angry Man");
                      break;
            case 'C':printf("Casabance");
                      break;
            case 'D':printf("Blood Diamond");
         }
        
    }
    Choose all that apply:

    A
    Pulp Fiction

    B
    12 Angry Man

    C
    Casabance

    D
    Blood Diamond

    E
    Compilation error

    Note: Consider on the expression: *(1+"AB" "CD"+1) = *(2+"AB" "CD") = *(2+"ABCD") =*("CD") ='C' Note: Case expression can be character constant.
    1. Report
  6. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        char *str="ONE"
        str++;
        switch(str){
            case "ONE":printf("Brazil");
                    break;
            case "NE": printf("Toy story");
                    break;
            case "N":  printf("His Girl Friday");
                    break;
            case "E":  printf("Casino Royale");
         }  
    }
    Choose all that apply:

    A
    Brazil

    B
    Toy story

    C
    His Girl Friday

    D
    Casino Royale

    E
    Compilation error

    Note: Case expression cannot be string constant.
    1. Report
  7. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        switch(5||2|1){
            case 3&2:printf("Anatomy of a Murder");
                  break;
            case -~11:printf("Planet of Apes");
                   break;
            case 6-3<<2:printf("The conversation");
                   break;
        case 5>=5:printf("Shaun of the Dead");
         } 
    }
    Choose all that apply:

    A
    Anatomy of a Murder

    B
    Planet of Apes

    C
    The conversation

    D
    Shaun of the Dead

    E
    Compilation error

    Note: Consider on the expression: 5||2|1 =5|| (2|1) //Bitwise or has higher precedence =5||3 =1 Now, value of each case expression: 3&2 = 2 -~11 = -(-12) =12 6-3<<2 = 3 <<2 = 12 5>=5 = 1 case -~11 and case 6-3<<2 have same constant expression i.e. case 12 In c duplicate case is not possible.
    1. Report
  8. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        switch(6){
            case 6.0f:printf("Sangakkara");
                   break;
            case 6.0: printf("Sehwag");
                   break;
            case 6.0L:printf("Steyn");
                   break;
            default:  printf("Smith");
        } 
    }
    Choose all that apply:

    A
    Sangakkara

    B
    Sehwag

    C
    Steyn

    D
    Smith

    E
    Compilation error

    Note: Case expression must be integral constant expression. If it is not integer then it is automatically type casted into integer value. so. (int)6.0f = 6 (int)6.0 = 6 (int)6.0L = 6 In c duplicate case is not possible.
    1. Report
  9. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
        switch(0X0){
            case NULL:printf("Thierry Henry");
                 break;
            case '\0':printf("Steven Gerrend");
                 break;
            case 0: printf("Kaka");
                 break;
            default: printf("Michael Ballack");
        }
    }
    Choose all that apply:

    A
    Thierry Henry

    B
    Steven Gerrend

    C
    Kaka

    D
    Michael Ballack

    E
    Compilation error

    Note: Macro constant NULL has be defined as 0 in stdio.h ASCII value of character constant '\0' is 0 As we duplicate case is not possible in c.
    1. Report
  10. Question: What will be output when you will execute following c code?
    #include<stdio.h>
    void main(){
         switch(5/2*6+3.0){
            case 3:printf("David Beckham");
                 break;
            case 15:printf("Ronaldinho");
                 break;
            case 0:printf("Lionel Messi");
                 break;
            default:printf("Ronaldo");
         }  
    }
    Choose all that apply:

    A
    David Beckham

    B
    Ronaldinho

    C
    Lionel Messi

    D
    Ronaldo

    E
    Compilation error

    Note: Consider on the expression: 5/2*6+3.0 =2*6+3.0 =12 + 3.0 =15.0 In c switch expression must return an integer value. It cannot be float, double or long double
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd