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

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
C) compilation error
A) program displays 5 4 3 2 1
B) program displays 1 2 3 4 5
D) segmentation fault runtime exception

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
Anthony
4 hours ago
I thought it might run fine, but now I’m not so sure.
upvoted 0 times
...
Fabiola
5 days ago
I’m leaning towards option C too. It just doesn’t make sense.
upvoted 0 times
...
My
10 days ago
No way, it won't compile. Line 8 is definitely an issue.
upvoted 0 times
...
Levi
16 days ago
I feel like it should output 5 4 3 2 1.
upvoted 0 times
...
Gladys
21 days ago
Yeah, I agree. The order of parameters in assign is wrong.
upvoted 0 times
...
Lorrine
26 days ago
I think it will give a compilation error in line 8.
upvoted 0 times
...
Cassi
1 month ago
I think it's a runtime exception, not a compilation error.
upvoted 0 times
...
Leonardo
1 month ago
Nope, it outputs 1 2 3 4 5 if it compiles!
upvoted 0 times
...
Taryn
1 month ago
Wait, really? I thought it would just print the numbers.
upvoted 0 times
...
Aliza
2 months ago
Totally agree, you can't use `at()` on a list!
upvoted 0 times
...
Lawanda
2 months ago
The program will actually have a compilation error in line 8.
upvoted 0 times
...
Fernanda
2 months ago
I think it's option C for sure.
upvoted 0 times
...
Gary
2 months ago
Nope, it outputs nothing because of that error.
upvoted 0 times
...
Blythe
2 months ago
Wait, really? I thought it would just output the numbers.
upvoted 0 times
...
Crista
4 months ago
Totally agree, you can't use `at()` on a list!
upvoted 0 times
...
Jordan
4 months ago
The code will actually cause a compilation error in line 8.
upvoted 0 times
...
Lourdes
4 months 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
5 months 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
5 months 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
5 months 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