If there is one, point out an error in the program
#include
using namespace std;
int main()
{
int c = 'a';
switch(i)
{
case '2':
cout<<"OK";
case '1':
cout<<"Error";
default:
break;
}
return 0;
}
Suggested Answer: B
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
23 comments · newest first
SH
Sharita
10 months ago
Wait, are we sure there's no other error?
TR
Troy
10 months ago
Totally agree, that's a major error!
DO
Domitila
10 months ago
The variable 'i' is undeclared, that's a big issue.
SH
Shawn
10 months ago
Isn't 'c' supposed to be used in the switch?
DA
Darell
11 months ago
I think the switch statement is fine, just fix 'i'.
CH
Charlesetta
11 months ago
I feel like I’ve seen a similar question before, and it was about undeclared identifiers, so maybe that's the error here too.
MA
Malcom
11 months ago
I’m a bit confused; I thought 'continue' was only used in loops, so I don’t think that’s the problem here.
HE
Heidy
11 months ago
I remember something about switch statements, but I’m not sure if there’s an error with the case labels.
MA
Mammie
11 months ago
I think there’s an issue with the variable 'i' since it’s not declared anywhere in the program.
SL
Slyvia
12 months ago
I'm feeling pretty confident about this one. The error is clearly the use of the undeclared variable 'i' in the switch statement. I'll make a note to always double-check variable declarations when analyzing code.
MI
Miriam
12 months ago
Ah, I see the problem now. The variable 'i' is not defined, so the switch statement won't work as expected. I'll make sure to check for any undeclared variables when reviewing code on the exam.
AL
Alba
12 months ago
Okay, I think I've got it. The issue is that the variable 'i' is used in the switch statement, but it's never declared or initialized. That's gotta be the error they're looking for.
CA
Carma
1 year ago
Uh oh, I'm a bit confused here. The question mentions an error, but I'm not sure I see one right away. I'll have to double-check the syntax and variable declarations.
JU
Justine
1 year ago
Hmm, this looks tricky. I'll need to carefully read through the code and think about the use of the switch statement and the variable 'i'.
WH
Whitley
1 year ago
I think the error is in the line 'switch(i)' because 'i' is not declared anywhere in the program.
TA
Tawna
1 year ago
B) Use of undeclared identifier 'i'
GA
Galen
1 year ago
I'd say it's D. The 'break' statement inside the 'default' case is not necessary and could be considered an illegal use of it.
AL
Alfred
1 year ago
B) Use of undeclared identifier 'i'
MA
Magda
1 year ago
A) No Error
MA
Maia
1 year ago
Definitely B. The variable 'i' is not declared anywhere in the code, so it's a clear case of using an undeclared identifier.
JA
Jamie
1 year ago
A) No Error
TO
Tom
1 year ago
Yeah, definitely B. 'i' is nowhere to be found in the code.
EV
Evelynn
1 year ago
B) Use of undeclared identifier 'i'