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 50 Discussion

Posted by Graciela on Mar 08, 2026 at 03:29 AM

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

#include

#include

#include

using namespace std;

int main(void)

{

string s;

s = "Test";

s.resize (s.size() ? 1);

cout<

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
26 comments · newest first
AL
Alease 1 month ago
It definitely resizes the string, so it prints: Tes 3.
WH
Whitney 2 months ago
I feel like there's a compilation error.
DA
Dan 2 months ago
No way, it should print: Tes 3.
LE
Leota 2 months ago
I think it prints: Test 4.
WI
Wilbert 2 months ago
Definitely not a compilation error. It resizes to 1, so it prints: Tes 3.
MA
Malcom 2 months ago
I feel like there's a resize issue. Maybe a compilation error?
WI
William 2 months ago
No way, it should print: Tes 3.
LI
Linwood 3 months ago
I think it prints: Test 4.
MI
Miesha 3 months ago
Definitely D, it prints: Tes 3.
BR
Brittni 3 months ago
I feel like there's a resize issue here.
LO
Lore 3 months ago
No way, it should be Test 3.
PE
Pearlie 3 months ago
I think it prints: Test 4.
ME
Melina 3 months ago
Definitely not a compilation error, that's for sure.
TA
Tamra 4 months ago
I thought it would print the whole string!
CA
Carissa 5 months ago
Wait, how does it not throw an error?
TI
Timothy 5 months ago
Totally agree, the string gets resized!
GL
Glory 5 months ago
It prints: Tes 3
RI
Richelle 6 months ago
Not sure about that, seems like it should keep more characters.
VO
Vonda 6 months ago
Definitely option D, resizing to 1 keeps the first character.
TE
Terrilyn 6 months ago
Wait, why does it print "Tes"? That's weird!
MA
Mable 6 months ago
I think it should be a compilation error.
AN
Annelle 6 months ago
It prints: Tes 3
CH
Charisse 6 months ago
I’m a bit confused about the condition in the resize function. Does it really change the string to just one character? I need to think this through.
XO
Xochitl 7 months ago
I practiced a similar question where resizing a string affected its content. I feel like it might print "Tes 3" because of that.
VA
Valentine 7 months ago
I remember something about the resize function. It might change the string size, but I can't recall if it keeps the original characters.
FL
Fletcher 7 months ago
I think the code should compile fine since it looks correct, but I'm not sure what the output will be.
0/2000 characters

Save Cancel