New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPA-21-02 Exam - Topic 8 Question 31 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 31
Topic #: 8
[All CPA-21-02 Questions]

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int main()

{

int i=5;

switch(i)

{

case 1:

cout<<"Hello";

break;

case 2:

cout<<"world";

break;

case 3:

break;

default:

cout<<"End";

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Glenn
3 months ago
Nah, it definitely prints "End".
upvoted 0 times
...
Vicente
3 months ago
I thought it would print something for case 3!
upvoted 0 times
...
Effie
3 months ago
Wait, why doesn't it print anything else?
upvoted 0 times
...
Dannette
4 months ago
Totally agree, the switch doesn't match any case.
upvoted 0 times
...
Thersa
4 months ago
It prints: End.
upvoted 0 times
...
Esteban
4 months ago
I thought the default case only runs if no other cases match, so yeah, I guess it should print "End" in this situation.
upvoted 0 times
...
Dante
4 months ago
I'm not entirely sure, but I feel like it might print something else if there's a fall-through, but in this case, it seems like it won't.
upvoted 0 times
...
Huey
4 months ago
I remember practicing a similar question, and I believe it should print "End" because none of the cases match.
upvoted 0 times
...
Tyisha
5 months ago
I think the switch statement will just skip all cases since `i` is 5, so it might go to the default case.
upvoted 0 times
...
Titus
5 months ago
Alright, I've got this. The variable 'i' is set to 5, and the switch statement checks the value of 'i'. Since 5 doesn't match any of the case values, the default case will be executed, which prints "End". I'm confident that's the correct answer.
upvoted 0 times
...
Ardella
5 months ago
Hmm, I'm not entirely sure about this one. The switch statement looks straightforward, but I'm wondering if there's some edge case or nuance I'm missing. I'll need to carefully re-read the code and think it through before answering.
upvoted 0 times
...
Ethan
5 months ago
Okay, let me break this down step-by-step. The variable 'i' is set to 5, and the switch statement checks the value of 'i'. Since 5 doesn't match any of the case values (1, 2, or 3), the default case will be executed, which prints "End". I think I've got it now.
upvoted 0 times
...
Kattie
5 months ago
I'm a bit confused here. The switch statement has cases for 1, 2, and 3, but the variable 'i' is set to 5. Does that mean the default case will be executed, or is there something I'm missing?
upvoted 0 times
...
Linette
5 months ago
Hmm, let me think this through. The variable 'i' is initialized to 5, so the default case should be executed, which prints "End". I'm pretty confident that's the correct answer.
upvoted 0 times
...
Billye
1 year ago
The correct answer is C. The code will print 'End' because the value of 'i' is 5, which doesn't match any of the case statements, so it will execute the default case.
upvoted 0 times
Jerilyn
1 year ago
D) It prints: Helloworld
upvoted 0 times
...
Gilma
1 year ago
C) It prints: End
upvoted 0 times
...
Audry
1 year ago
B) It prints: world
upvoted 0 times
...
Pura
1 year ago
A) It prints: Hello
upvoted 0 times
...
...
Donte
1 year ago
I believe it will print: End as well, since the default case will be executed when no other case matches.
upvoted 0 times
...
Annamae
1 year ago
Haha, I bet the answer is D. It will print 'Helloworld' because the code is clearly broken and will do something unexpected. That's what happens when you write spaghetti code!
upvoted 0 times
...
Inocencia
1 year ago
I think the answer is B. The code will print 'world' because the value of 'i' is 5, which matches the case 2 statement.
upvoted 0 times
Leota
1 year ago
Because the value of 'i' is 5, which matches the case 2 statement.
upvoted 0 times
...
Katheryn
1 year ago
The code will print 'world'.
upvoted 0 times
...
Na
1 year ago
I think the answer is B.
upvoted 0 times
...
...
Antonio
1 year ago
I agree with Tamala, because the value of i is 5 and there is no case for 5 in the switch statement.
upvoted 0 times
...
Tamala
1 year ago
I think it will print: End.
upvoted 0 times
...
Arlyne
1 year ago
The answer is C. The code will print 'End' because the value of 'i' is 5, which doesn't match any of the case statements, so it will execute the default case.
upvoted 0 times
Abraham
1 year ago
It's a common mistake, but the default case will be executed in this code.
upvoted 0 times
...
Dortha
1 year ago
I would have guessed 'Hello' at first.
upvoted 0 times
...
Franchesca
1 year ago
Yes, you're right. The code will print 'End'.
upvoted 0 times
...
Carri
1 year ago
I think the answer is C.
upvoted 0 times
...
...

Save Cancel