Switch case MCQ 15: Characters are allowed



Switch case MCQ 15: Characters are allowed


Problem Statement 15 : Characters are allowed

void main()
{
 char choice = 'a' ;
 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 for character Variable

  1. Yes
  2. No

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


Explanation :

  1. First Rule of Using Switch is that Integer are Characters are allowed .
  2. Generally Case Label Should be Integer / Constant , And Character can be converted into Integer (ASCII value)
  3. Thus above code is absolutely Correct .