C Programming MCQ : Switch Case Multiple Choice Questions

Question 11
Guess the Output of the Following Program -
#include<stdio.h>
#define var 1
void main()
{
 int choice = 1 ;
 switch(choice)
 {
  case var: 
        printf("\I am in Case 1");
        break;
  case 2:
        printf("\nI am in Case 2");
        break;
  case 3:
        printf("\nI am in Case 3");
        break;
 }
}
A
Run Time Error
B
I am in Case 1
C
I am in Case 3
D
I am in Case 2
E
Compile Error
Question 11 Explanation: 
  1. #define is called as Preprocessor
  2. Before Executing Program Macro processor just replaces the 'var' by its eqivalent definition
  3. Here 'var' is replaced by 1 and case 1 will be executed
Question 12
Guess the Output of the Following Program -
#include<stdio.h>
void main()
{
 int choice = 1 ;
 int const var = 2;  
 switch(choice)
 {
  case 1: 
        printf("\This is Roll No - 1");
        break;
  case var:
        printf("\This is Roll No - 2");
        break;
  case 3:
        printf("\This is Roll No - 3");
        break;
 }
}
A
Run Time Error
B
This is Roll No - 1
C
This is Roll No - 3
D
Compile Time Error
E
This is Roll No - 2
Question 12 Explanation: 
  1. Variable declared with const is allowed in the Switch Case.
  2. Variable declared with const will have permanent value after the first initialization.
Question 13
Guess the Output of the Following Program -
void main()
{
 int choice = 1 ;
 switch(choice,choice+1,choice+2)
 {
  case var: 
        printf("\nThis is Paramete 1");
        break;
  case 2:
        printf("\nThis is Paramete 2");
        break;
  case 3:
        printf("\nThis is Paramete 3");
        break;
 }
}
A
This is Paramete 3
B
Compile Error
C
No Output
D
This is Paramete 2
E
This is Paramete 1
Question 13 Explanation: 
  1. Comma Returns Rightmost Operand
  2. Rightmost variable is 'choice+2' so it returns 'choice+2'
  3. Thus Case 3 will be executed
Question 14
Point out the Error in the following Code -
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;
 }
}
A
Switch Case Does not contain any blank case.
B
No Error
C
Uppercase and Lowercase Characters cannot be used together.
D
Character is not allowed in switch case as "Case Label"
Question 14 Explanation: 
case 'A' and case 'a' Share same set of statements because of single break statement.
Question 15
Is program is error free ? - (Character Variable is passed to switch)
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;
 }
}
A
Yes
B
No
Question 15 Explanation: 
  1. Switch case can accept Integer are Characters as case Label and as parameter.
  2. Character Type in C can be converted into Integer called ASCII value.