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 Exam CPP Topic 9 Question 97 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 97
Topic #: 9
[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);

dequed1;

d1.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:

Stevie
7 days ago
The output should be 1 2 3 4 5, as the `assign()` function of `deque` copies the elements from the `vector` in the same order.
upvoted 0 times
...
India
8 days ago
But doesn't d1.assign(v1.end(), v1.begin()) reverse the order? So, it should be A).
upvoted 0 times
...
Ressie
10 days ago
No, I believe the correct answer is B) program outputs 1 2 3 4 5.
upvoted 0 times
...
India
12 days ago
I think the answer is A) program outputs 5 4 3 2 1.
upvoted 0 times
...

Save Cancel