Switch case MCQ 18: Both Int and Char in same switch is allowed
Switch case MCQ 18: Both Int and Char in same switch is allowed
Problem Statement 18 : Both Int and Char in same switch is allowed
void main() { int choice = -2 ; switch(choice) { case 1: printf("\nCase -1"); break; case '1': printf("\nCase -2"); break; } }
Options : Is it working properly ?
- Yes
- No
[toggle title=”Output”]Yes[/toggle]
How ? Why ?
- Generally Case Label Should be Integer / Constant
- Characters are Converted into Integer internally using ASCII
- Here there will be two case in above Program i.e Case 1 & case 49
- 49 is the ASCII value of ‘1’