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
- Yes
- No
[toggle title=”Output”]Yes[/toggle]
Explanation :
- First Rule of Using Switch is that Integer are Characters are allowed .
- Generally Case Label Should be Integer / Constant , And Character can be converted into Integer (ASCII value)
- Thus above code is absolutely Correct .