Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. What will be the output of the following C program segment?
    char inChar = ‘A’;
    switch (inChar) {
    case ‘A’ : prinf(“Choice A\n”);
    case ‘B’ :
    case ‘C’ : printf (“Choice B’):
    case ‘D’ :
    case ‘E’ :
    default: printf (“No Choice”);}
    1. No choice
    2. Choice A
    3. Choice A choice B No choice
    4. Program gives no output as it is erroneous
Correct Option: C

In switch case statements, there can be more cases, which case satisfied the condition will be executed, so we have to add break statement after every case in switch. If there is no break statement then all switch cases will be executed and default case will also be executed.
In the given program, there is no error so, case A is executed then case B and then case C and then case D and E and finally the default case will be executed and print.



Your comments will be displayed only after manual approval.