Switch case MCQ 14: Multiple Cases and One Break



Switch case MCQ 14: Multiple Cases and One Break


Problem Statement 14 : Multiple Cases and One Break

void main()
{
int choice = 1 ;
    switch(choice)
    {
      case 'A':
      case 'a':
            printf("\nA for Apple");
            break;
      case 'B':
      case 'b':
            printf("\nB for Ball");
            break;
    }
}

Options : Will this program works

  1. Yes
  2. No

[spoiler title=”Output”]Yes[/spoiler]


Explanation :

  1. We know that switch case executes from top to bottom
  2. Suppose Control is in case ‘A’ , As break statement is absent control will continues to execute case ‘a’ 
  3. As break statement encounters Control goes outside the loop
  4. So case ‘A’ and case ‘a’ Share same set of statements