Switch case MCQ 16: Constant Expressions are allowed



Switch case MCQ 16: Constant Expressions are allowed


Problem Statement 16 : Constant Expressions are allowed

void main()
{
 int choice = 2 ;
   switch(choice)
   { 
   case 1+2/3: 
        printf("\nCase 1");
        break;
   case 2/2*3:
        printf("\nCase 3");
        break;
   }
}

Options : Does Expressions are allowed in Case Labels

  1. Yes
  2. No

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


How and Why ?

  1. Generally Case Label Should be Integer / Constant
  2. As Constant Expression in Case Labels Results in Constant Value .
  3. Thus above code is absolutely Correct .