Question 1
Guess the Output of Following Program - (Select Two Options)
void main()
{
 int choice = 1 ;
 int a = 2;
 switch(choice)
 {
  case 1 :
        printf("\nC Programming is Very Funny Language");
        break;
  case 1 :
        printf("\n3 Idiots is Funny Movie");
        break;
  case a :
        printf("\nMy name is Pritesh A Taral");
        break;
 }
}
A
No continue statement in Statement
B
All Cases in switch are not unique
C
Default is absent
D
Variables are not allowed in Case Labels
Question 2
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
I am in Case 1
B
Run Time Error
C
I am in Case 2
D
I am in Case 3
E
Compile Error
Question 2 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 3
Guess the Output of the Following Program -
void main()
{
 int choice = 2 ;
 switch(choice);
 {
  case 1 :
        printf("\nAllas");
        break;
  case 2 :
        printf("\nBabo");
        break;
  case 3 :
        printf("\nHurray");
        break;
 }
 printf(" Finally I am in main ");
}
A
Finally I am in main
B
Allas Finally I am in main
C
Hurray Finally I am in main
D
None Of these
E
Babo Finally I am in main
Question 3 Explanation: 
Semicolon at the end of switch will terminate switch block without entering in it
Question 4
Guess the Output -
void main()
{
 int choice = 2 ;
 int Num = 3;
 switch(choice)
 {
  case 1 :
        printf("\nSachin Tendulkar is good Cricketer");
        break;
  case Num :
        printf("\nVariable is not allowed in Case");
        break;
  case 7-8+3 :
        printf("\nWhat do you Think ?");
        break;
 }
}
A
Run Time Error
B
Compile Error
C
Variable is not allowed in Case
D
Sachin Tendulkar is good Cricketer
E
What do you Think ?
Question 4 Explanation: 
Variables in switch case , not allowed !!
Question 5
Guess the Output of the following C Program -
void main()
{
 int choice = 1 ;
 switch(choice)
 {
        printf("\nI am in switch");
  case 1 :
        printf("\nWhat are You Doing in Mumbai");
        break;
  case 2 :
        printf("\nUS is Great Country");
        break;
  case 3 :
        printf("\nWater turns into Gas");
        break;
 }
}
A
Run Time Error
B
No Output
C
I am in switch What are You Doing in Mumbai
D
What are You Doing in Mumbai
E
Compile Error
Question 5 Explanation: 
  1. Every Statement in switch must be wrapped within any of the case
  2. I am in switch statement is not under any of the case so it is Neglected by Compiler
Question 6
Is following Code is Error Free ?
void main()
{
 int choice = 2 ;
 switch(choice)
  {
  }
}
A
Yes
B
No
Question 6 Explanation: 
There can exist Switch Without Case
Question 7
Guess the Output -
void main()
{
 int choice = 1 ;
 switch(choice<<1)
 {
  case 2:
        printf("\nAllas");
        break;
  case 4:
        printf("\nBabo");
        break;
  case 8:
        printf("\nHurray");
        break;
 }
}
A
Hurray
B
Allas
C
Compile Error : << is not allowed
D
Babo
Question 7 Explanation: 
  1. Integer Requires 2 bytes of memory
  2. Choice = 1 , Binary Representation ( 0000 0000 0000 0001 )
  3. After shifting above binary representation towards left by 1 bit (0000 0000 0000 0010)
  4. Equivalent decimal value of the above binary representation is 2
  5. So case 2 will be executed
Question 8
Guess the Output of the Following Program -
void main()
{
 int choice = 2 ;
 switch(choice)
 {
  case 1,2,1 :
        printf("\nAllas");
        break;
  case 1,3,2 :
        printf("\nBabo");
        break;
  case 4,5,3 :
        printf("\nHurray");
        break;
 }
}
A
Babo
B
Hurray
C
Compile Error : Multiple Parameter's not allowed
D
Allas
E
Run Time Error
Question 8 Explanation: 
  1. Multiple Numbers in cases are separated by comma
  2. Comma Returns Rightmost number
  3. case 1,2,3 will returns 3
Because of this -
case 1,2,3
&
case 2,3,3
both are two same cases.
Question 9
Guess the Output of the Following Program -
void main()
{
 int choice = 7 ;
 switch(choice)
 {
  default :
        printf("\nI am in Default");
  case 1 :
        printf("\nI am in case 1");
        break;
  case 2 :
        printf("\nI am in case 2");
        break;
  case 3 :
        printf("\nI am in case 3");
        break;
 }
}
A
Compile Error
B
I am in Default
C
I am in Default
I am in Main
D
Compile will not print anything.
E
None of These
Question 9 Explanation: 
default case may be placed at any position in the Switch case. Switch Case Label Sequence does not affect the flow execution.
Question 10
Guess the Output of the Following -
void main()
{
 int choice = 2 ;
 switch(choice)
 {
  case 1 :
        printf("\nAllas");
        break;
  case 2 :
        printf("\nBabo");
        continue;
  case 3 :
        printf("\nHurray");
        break;
 }
}
A
Babo
B
Hurray
C
Allas
D
Run Time Error
E
Compile Time Error
Question 10 Explanation: 
Compile Time Error : Misplaced Else
Question 11
Is this program is Error Free ?
void main()
{
 int choice = 2 ;
 switch(choice)
 {
  case 1 :
        printf("\nYour Time Starts now");
        break;
  case 7-8+3 :
        printf("\nWhy to Learn C Programming");
        break;
  case 9/3 :
        printf("\nDon't Use Pointer");
        break;
 }
}
A
No
B
Yes
Question 11 Explanation: 
  1. Constant Expression is absolutely allowed
  2. Variable included in Expression is not allowed as Constant Expression
  3. 7-8+3 = 2 so case 2 will be evaluated
There are 11 questions to complete.