Deal of The Day! 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 3 Question 55 Discussion

What is the output of the program if character 4 is supplied as input?#include using namespace std;int main () {int c;cin >> c;try{switch (c){case 1:throw 20;case 2:throw 5.2f;case 3:throw 'a';default:cout
D) It prints: No exception
A) It prints: float exception. Exception Nr.
B) It prints: int exception. Exception Nr.
C) It prints: An exception occurred

C++ Institute CPA-21-02 Exam - Topic 3 Question 55 Discussion

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

What is the output of the program if character 4 is supplied as input?

#include

using namespace std;

int main () {

int c;

cin >> c;

try

{

switch (c)

{

case 1:

throw 20;

case 2:

throw 5.2f;

case 3:

throw 'a';

default:

cout<<"No exception";

}

}

catch (int e)

{ cout << "int exception. Exception Nr. " << e; }

catch (float e)

{ cout << "float exception. Exception Nr. " << e; }

catch (...)

{ cout << "An exception occurred."; }

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

0/2000 characters
Willetta
4 hours ago
I agree, it's clear in the code.
upvoted 0 times
...
Nathalie
5 days ago
But it won't, default case handles it.
upvoted 0 times
...
Maia
10 days ago
I feel like it should throw something.
upvoted 0 times
...
Javier
16 days ago
Yeah, because 4 doesn't match any case.
upvoted 0 times
...
Chandra
21 days ago
I think it prints: No exception.
upvoted 0 times
...
Kina
26 days ago
I thought it would throw something for sure!
upvoted 0 times
...
Yvonne
1 month ago
Yup, that's what I got too!
upvoted 0 times
...
Alverta
1 month ago
Wait, are you sure? What if there's a hidden exception?
upvoted 0 times
...
Shawn
1 month ago
Totally agree, default case handles it!
upvoted 0 times
...
Moon
2 months ago
It prints: No exception
upvoted 0 times
...
Shakira
2 months ago
I’m a bit confused about the catch blocks. If it hits the default, does it really just print "No exception" without throwing anything? That seems too straightforward!
upvoted 0 times
...
Teresita
2 months ago
I practiced a similar question where the default case was also involved. I feel like it should just output "No exception" since 4 isn't one of the cases.
upvoted 0 times
...
Carry
2 months ago
I'm not entirely sure, but I remember something about exceptions being thrown for specific cases. I guess 4 doesn't match any case, so maybe it just skips to the default?
upvoted 0 times
...
Carmela
2 months ago
I think if character 4 is input, it goes to the default case, right? So it should print "No exception".
upvoted 0 times
...

Save Cancel