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 CPP Exam - Topic 4 Question 122 Discussion

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
E) compilation error
A) program outputs: 10 0 10 0
B) program outputs: 0 0 0 0
C) program outputs: 10 10 10 10
D) program outputs: 10 0 0 10

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

Actual exam question for C++ Institute's CPP exam
Question #: 122
Topic #: 4
[All CPP Questions]

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;

}

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

0/2000 characters
Serita
5 days ago
Mylist is cleared, so it should show 0.
upvoted 0 times
...
Lilli
10 days ago
Yeah, because third is a copy of second, which has 10 elements.
upvoted 0 times
...
Gracie
15 days ago
I think it outputs 10 0.
upvoted 0 times
...
Hui
20 days ago
Definitely not a compilation error, it runs fine!
upvoted 0 times
...
Stephaine
25 days ago
Is there a compilation error? Seems odd.
upvoted 0 times
...
Maile
1 month ago
Wait, why does mydeck size become 0?
upvoted 0 times
...
Norah
1 month ago
I think it should be 10 0, 10 0.
upvoted 0 times
...
Albert
1 month ago
Looks like it outputs 10 0, 0 10.
upvoted 0 times
...
Reita
2 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.
upvoted 0 times
...
Laurene
3 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.
upvoted 0 times
...
Margurite
3 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.
upvoted 0 times
...
Shanda
3 months ago
I think the program should compile fine since all the includes are correct, but I'm not sure about the output.
upvoted 0 times
...

Save Cancel