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; } }
No continue statement in Statement | |
All Cases in switch are not unique | |
Default is absent | |
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; } }
I am in Case 1 | |
Run Time Error | |
I am in Case 2 | |
I am in Case 3 | |
Compile Error |
Question 2 Explanation:
- #define is called as Preprocessor
- Before Executing Program Macro processor just replaces the 'var' by its eqivalent definition
- 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 "); }
Finally I am in main | |
Allas Finally I am in main | |
Hurray Finally I am in main | |
None Of these | |
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; } }
Run Time Error | |
Compile Error | |
Variable is not allowed in Case | |
Sachin Tendulkar is good Cricketer | |
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; } }
Run Time Error | |
No Output | |
I am in switch
What are You Doing in Mumbai | |
What are You Doing in Mumbai | |
Compile Error |
Question 5 Explanation:
- Every Statement in switch must be wrapped within any of the case
- 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) { } }
Yes | |
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; } }
Hurray | |
Allas | |
Compile Error : << is not allowed | |
Babo |
Question 7 Explanation:
- Integer Requires 2 bytes of memory
- Choice = 1 , Binary Representation ( 0000 0000 0000 0001 )
- After shifting above binary representation towards left by 1 bit (0000 0000 0000 0010)
- Equivalent decimal value of the above binary representation is 2
- 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; } }
Babo | |
Hurray | |
Compile Error : Multiple Parameter's not allowed | |
Allas | |
Run Time Error |
Question 8 Explanation:
- Multiple Numbers in cases are separated by comma
- Comma Returns Rightmost number
- case 1,2,3 will returns 3
case 1,2,3&
case 2,3,3both 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; } }
Compile Error | |
I am in Default | |
I am in Default I am in Main | |
Compile will not print anything. | |
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; } }
Babo | |
Hurray | |
Allas | |
Run Time Error | |
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; } }
No | |
Yes |
Question 11 Explanation:
- Constant Expression is absolutely allowed
- Variable included in Expression is not allowed as Constant Expression
- 7-8+3 = 2 so case 2 will be evaluated
There are 11 questions to complete.