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:

Brittani
22 days ago
C'mon, this is a trick question, right? I mean, who writes code with `deque` and `vector` like that? Probably some mad scientist trying to break the laws of programming or something.
upvoted 0 times
...
Clement
23 days ago
I'm gonna go with option B, 1 2 3 4 5. Seems like the most straightforward answer, and I don't see any obvious bugs in the code. Gotta love it when the solution is just that simple!
upvoted 0 times
Shenika
23 hours ago
User1: I think it's option B, 1 2 3 4 5. Looks good to me.
upvoted 0 times
...
...
Diane
25 days ago
Whoa, this code is wild! I bet it'll blow up like a fireworks display, but in a really bad way. Segmentation fault, anyone?
upvoted 0 times
...
Lorriane
26 days ago
This code will not compile due to a syntax error in line 8. The correct order of the range should be `v1.begin(), v1.end()`.
upvoted 0 times
...
Stevie
2 months 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
Alishia
8 days ago
C) compilation error in line 8
upvoted 0 times
...
Georgeanna
11 days ago
B) program outputs 1 2 3 4 5
upvoted 0 times
...
Nida
28 days ago
A) program outputs 5 4 3 2 1
upvoted 0 times
...
...
India
2 months ago
But doesn't d1.assign(v1.end(), v1.begin()) reverse the order? So, it should be A).
upvoted 0 times
...
Ressie
2 months ago
No, I believe the correct answer is B) program outputs 1 2 3 4 5.
upvoted 0 times
...
India
2 months ago
I think the answer is A) program outputs 5 4 3 2 1.
upvoted 0 times
...

Save Cancel