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

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

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

#include

#include

#include

using namespace std;

int main ()

{

int t[] = {1, 2 ,3 ,4 ,5};

vectorv1(t, t+5);

listl1;

l1.assign(v1.end(), v1.begin());

for(int i=0; i

{

cout<

}

cout<

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Crista
11 hours ago
Totally agree, you can't use `at()` on a list!
upvoted 0 times
...
Jordan
6 days ago
The code will actually cause a compilation error in line 8.
upvoted 0 times
...
Lourdes
20 days ago
I think the loop on line 8 could cause a runtime error since `l1.size()` might not work as expected with a list.
upvoted 0 times
...
Krystal
25 days ago
I feel like there might be a compilation error because of the way `l1.assign` is used. It seems like the parameters are in the wrong order.
upvoted 0 times
...
Jamika
30 days ago
I remember practicing a similar question where we had to use `assign`, but I can't recall if the order of parameters matters.
upvoted 0 times
...
Mica
1 month ago
I think the code should compile fine, but I'm not sure about the output since the `assign` method seems a bit confusing.
upvoted 0 times
...

Save Cancel