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
1 months 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
1 months 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
Paz
11 days ago
User3: I'm going with B too. Simple and straightforward.
upvoted 0 times
...
Leatha
13 days ago
User2: Yeah, I agree. The code seems fine, so B sounds right.
upvoted 0 times
...
Shenika
16 days ago
User1: I think it's option B, 1 2 3 4 5. Looks good to me.
upvoted 0 times
...
...
Diane
1 months 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
1 months 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
Coral
3 days ago
A) program outputs 5 4 3 2 1
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
23 days ago
C) compilation error in line 8
upvoted 0 times
...
Georgeanna
27 days ago
B) program outputs 1 2 3 4 5
upvoted 0 times
...
Nida
1 months 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
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77