BLACK FRIDAY SALE – Unlock Up to 25% OFF on All Exam Prep! - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPP Exam - Topic 4 Question 122 Discussion

Posted by Desmond on May 05, 2026 at 02:09 AM

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

#include

#include

#include

#include

#include

using namespace std;

int main()

{

int t[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

deque mydeck(t, t+10);list mylist(t,t+10);

queue first;

queue second(mydeck);

queue third(second);

queue > fourth(mylist);

mylist.clear();third.clear();

cout<

cout<

return 0;

}

Suggested Answer: E

Get Premium CPP Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
27 comments · newest first
VA
Valentin 1 month ago
Right, so A is the best choice.
JO
Johnetta 1 month ago
But fourth should have 10 since it’s initialized with mylist before clearing.
BE
Bernardo 1 month ago
What about option D? It shows mylist as 0.
CA
Catrice 2 months ago
I agree, E seems unlikely.
FR
Francisca 2 months ago
I doubt it’s a compilation error. All includes are fine.
CH
Chantell 2 months ago
I feel like it could be a trick question.
LE
Lezlie 2 months ago
Exactly! So, option A makes sense.
VA
Valentin 2 months ago
But mylist is cleared, so it should show 0.
GE
Georgeanna 3 months ago
Yeah, because third is a copy of second, which has 10 elements.
JO
Johnetta 3 months ago
I think it outputs 10 0.
SU
Suzan 3 months ago
Compilation error seems unlikely; all syntax looks fine.
FR
Frankie 3 months ago
I feel confident about option A too.
LY
Lynna 3 months ago
No, fourth is initialized before mylist is cleared. It should still show 10.
YU
Yuriko 3 months ago
What if it’s option D? Mylist is cleared but fourth is based on it.
LE
Leila 4 months ago
I agree, option A makes sense.
SE
Serita 4 months ago
Mylist is cleared, so it should show 0.
LI
Lilli 4 months ago
Yeah, because third is a copy of second, which has 10 elements.
GR
Gracie 4 months ago
I think it outputs 10 0.
HU
Hui 4 months ago
Definitely not a compilation error, it runs fine!
ST
Stephaine 4 months ago
Is there a compilation error? Seems odd.
MA
Maile 5 months ago
Wait, why does mydeck size become 0?
NO
Norah 5 months ago
I think it should be 10 0, 10 0.
AL
Albert 5 months ago
Looks like it outputs 10 0, 0 10.
RE
Reita 5 months ago
I’m not entirely sure, but I think the output could be option D since `third` is a copy of `second`, and `mylist` is cleared.
LA
Laurene 7 months ago
I practiced a similar question where clearing a container affected the size. I feel like the output might be option A, but I can't recall exactly.
MA
Margurite 7 months ago
I remember something about queues and how they manage their size. I think `third.size()` should return 10, but I'm confused about `mylist.size()` after clearing it.
SH
Shanda 7 months ago
I think the program should compile fine since all the includes are correct, but I'm not sure about the output.
0/2000 characters

Save Cancel