1. What will be the output of the following code?
int x = 2;
switch(x) {
case 1: cout << "One"; break;
case 2: cout << "Two"; break;
case 3: cout << "Three"; break;
}
(A) One
(B) Two
(C) Three
(D) Error
2. What will the following program print?
int num = 5;
switch(num) {
case 1: cout << "A"; break;
case 5: cout << "B"; break;
default: cout << "C";
}
(A) A
(B) Error
(C) C
(D) B
3. What will be printed?
int x = 10;
switch(x) {
case 5: cout << "Five"; break;
case 10: cout << "Ten"; break;
default: cout << "None";
}
(A) Five
(B) None
(C) Ten
(D) Error
4. What happens when the code runs?
int x = 3;
switch(x) {
case 1: cout << "A";
case 2: cout << "B";
case 3: cout << "C";
}
(A) C
(B) ABC
(C) BC
(D) C followed by nothing
5. What will this code output?
int val = 2;
switch(val) {
case 1: cout << "X"; break;
case 2: cout << "Y";
case 3: cout << "Z"; break;
default: cout << "W";
}
(A) Y
(B) Error
(C) YZW
(D) YZ
6. Identify the output:
int x = 4;
switch(x) {
case 1: cout << "A"; break;
case 2: cout << "B"; break;
default: cout << "C";
}
(A) A
(B) B
(C) C
(D) Error
7. Which statement is true about the following code?
int x = 5;
switch(x) {
case 5: cout << "Hello";
case 6: cout << "World";
}
(A) HelloWorld
(B) Hello
(C) World
(D) Error
8. What will be printed?
int a = 1;
switch(a + 1) {
case 1: cout << "One"; break;
case 2: cout << "Two"; break;
default: cout << "Other";
}
(A) One
(B) Two
(C) Other
(D) Error
9. What is the output?
int n = 0;
switch(n) {
case 0: cout << "Zero"; break;
case 1: cout << "One"; break;
default: cout << "Other";
}
(A) Zero
(B) One
(C) Other
(D) Error
10. What will happen when this code executes?
char ch = 'B';
switch(ch) {
case 'A': cout << "Apple"; break;
case 'B': cout << "Banana"; break;
default: cout << "Other";
}
(A) Apple
(B) Error
(C) Other
(D) Banana
11. What will the following output?
int n = 2;
switch(n * 2) {
case 2: cout << "Two"; break;
case 4: cout << "Four"; break;
default: cout << "None";
}
(A) Two
(B) Four
(C) None
(D) Error
12. What happens in this case?
int n = 1;
switch(n) {
case 1:
case 2: cout << "Match"; break;
default: cout << "No match";
}
(A) Match
(B) No match
(C) Error
(D) Nothing
13. Identify the error in this code:
float x = 1.5;
switch(x) {
case 1: cout << "One"; break;
case 2: cout << "Two"; break;
}
(A) switch expression must be integer or enum type
(B) Missing default
(C) Missing break
(D) No error
14. What will be printed?
int num = 7;
switch(num) {
case 5: cout << "Five"; break;
case 7: cout << "Seven"; break;
default: cout << "None";
}
(A) Five
(B) Error
(C) None
(D) Seven
15. What will this code produce?
int val = 9;
switch(val) {
case 10: cout << "Ten"; break;
case 11: cout << "Eleven";
default: cout << "Default";
}
(A) Ten
(B) Eleven
(C) Default
(D) ElevenDefault
16. What is the output of the following?
int n = 3;
switch(n) {
case 1: cout << "One";
case 2: cout << "Two";
case 3: cout << "Three";
default: cout << "Done";
}
(A) ThreeDone
(B) Done
(C) OneTwoThree
(D) Three only
17. What will happen here?
int x = 10;
switch(x) {
case 5: cout << "Five";
case 10: cout << "Ten"; break;
case 15: cout << "Fifteen";
}
(A) Ten
(B) TenFifteen
(C) FiveTen
(D) Error
18. What is the output?
int x = 1;
switch(x) {
case 0: cout << "Zero"; break;
case 1: cout << "One";
default: cout << "End";
}
(A) OneEnd
(B) One
(C) End
(D) Error
19. What happens when this code runs?
int x = 2;
switch(x) {
case 1: cout << "Case1";
case 2: cout << "Case2";
case 3: cout << "Case3";
default: cout << "Default";
}
(A) Case2Case3Default
(B) Case2
(C) Case3Default
(D) Default
20. What will be printed?
int a = 4;
switch(a) {
case 2: cout << "Two"; break;
case 4: cout << "Four"; break;
case 6: cout << "Six"; break;
default: cout << "Other";
}
(A) Two
(B) Four
(C) Six
(D) Other