C Programming MCQ : Switch Case Multiple Choice Questions

Question 16
State whether following code will execute or not ?
void main()
{
 int choice = 2 ;
 switch(choice)
  {
  case 1+2/3 :
            printf("\nCase 1");
            break;
  case 2/2*3 :
            printf("\nCase 3");
            break;
  }
}
A
Yes
B
No
Question 16 Explanation: 
  1. Case Label Should be Integer / Constant
  2. Constant Expression in Case Labels Must Results in Constant Value
case 1+2/3=case(1+0)
           =case1
case2/2*3=case(1*3)
           =case3
Question 17
State whether following code is error free or not -
void main()
{
 int choice = -2 ;
 switch(choice)
  {
  case -1 :
            printf("\nCase -1");
            break;
  case -2 :
            printf("\nCase -2");
            break;
  }
}
A
No
B
Yes
Question 17 Explanation: 
Switch case can have negative case labels.
Question 18
Check whether code will work properly or not -
void main()
{
 int choice = 1 ;
 switch(choice)
  {
  case 1 :
            printf("\nCase Integer 1");
            break;
  case '1' :
            printf("\nCase Character 1");
            break;
  }
}
A
Yes
B
No
Question 18 Explanation: 
  1. Case Label Should be Integer / Constant in case of character.
  2. Characters are Converted into Integer internally using ASCII
case 1=case1
case'1'=case(ASCII Value of Digit 1)
         =case49
Question 19
Check whether following code will generate any output or not ?
void main()
{
 int choice = 10 ;
 switch(choice) 
  {
  case <10 :
            printf("\nLess than 10");
            break;
  case =10 :
            printf("\nEqual to 10");
            break;
  case >10 :
            printf("\nGreater than 10");
            break;
  }
}
A
No
B
Yes
Question 19 Explanation: 
  • Case Labels won't allow you to use Comparison Operators
Question 20
Check whether code will work properly or not -
void main()
{
 float choice = 10.1 ;
 switch(choice)
  {
  case 10.1 :
            printf("\nCase 10.1");
            break;
  case 10.2 :
            printf("\nCase 10.2");
            break;
  case 10.3 :
            printf("\nCase 10.3");
            break;
  }
}
A
Yes
B
No
Question 20 Explanation: 
  • Case Labels should not contain Floating Number