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

Posted by Michael on May 27, 2026 at 02:44 AM

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;

}

Suggested Answer: D

Get Premium CPA-21-02 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
17 comments · newest first
JA
Javier 25 days ago
Simple logic, really.
CH
Chandra 1 month ago
Exactly! No exceptions thrown.
BR
Brice 1 month ago
So, option D is correct then?
WI
Willetta 1 month ago
I agree, it's clear in the code.
NA
Nathalie 2 months ago
But it won't, default case handles it.
MA
Maia 2 months ago
I feel like it should throw something.
JA
Javier 2 months ago
Yeah, because 4 doesn't match any case.
CH
Chandra 2 months ago
I think it prints: No exception.
KI
Kina 2 months ago
I thought it would throw something for sure!
YV
Yvonne 2 months ago
Yup, that's what I got too!
AL
Alverta 3 months ago
Wait, are you sure? What if there's a hidden exception?
SH
Shawn 3 months ago
Totally agree, default case handles it!
MO
Moon 3 months ago
It prints: No exception
SH
Shakira 3 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!
TE
Teresita 3 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.
CA
Carry 3 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?
CA
Carmela 4 months ago
I think if character 4 is input, it goes to the default case, right? So it should print "No exception".
0/2000 characters

Save Cancel