Question 1
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
Character is not allowed in switch case as "Case Label"
D
Uppercase and Lowercase Characters cannot be used together.
Question 1 Explanation: 
case 'A' and case 'a' Share same set of statements because of single break statement.
Question 2

Switch Case Label should be Unique

State Whether True/False ?
A
True
B
False
Question 2 Explanation: 
Switch Case Label Should be Unique.
Question 3
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 3 Explanation: 
  • Case Labels won't allow you to use Comparison Operators
Question 4
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 4 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.
Question 5
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
No
B
Yes
Question 5 Explanation: 
  • Case Labels should not contain Floating Number
Question 6
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 2
B
No Output
C
This is Paramete 3
D
Compile Error
E
This is Paramete 1
Question 6 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 7
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
This is Roll No - 2
B
Compile Time Error
C
This is Roll No - 1
D
Run Time Error
E
This is Roll No - 3
Question 7 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 8
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 8 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 9
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 9 Explanation: 
Switch case can have negative case labels.
Question 10
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 10 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
There are 10 questions to complete.