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

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

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;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

0/2000 characters
Terrilyn
3 days ago
Wait, why does it print "Tes"? That's weird!
upvoted 0 times
...
Mable
8 days ago
I think it should be a compilation error.
upvoted 0 times
...
Annelle
13 days ago
It prints: Tes 3
upvoted 0 times
...
Charisse
19 days 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.
upvoted 0 times
...
Xochitl
24 days ago
I practiced a similar question where resizing a string affected its content. I feel like it might print "Tes 3" because of that.
upvoted 0 times
...
Valentine
29 days 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.
upvoted 0 times
...
Fletcher
1 month ago
I think the code should compile fine since it looks correct, but I'm not sure what the output will be.
upvoted 0 times
...

Save Cancel