What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main ()
{
int t[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
vector
deque
deque
d2 = d1;
d2.insert(d1.rbegin(), 10);
for(int i = 0; i { cout< } return 0; }
Suggested Answer: D
Get Premium CPP Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
28 comments · newest first
MI
Miesha
8 months ago
I’m leaning towards D. There might be a compilation issue.
CH
Chana
9 months ago
No way, it’s option C. The loop only prints d1.
ON
Onita
9 months ago
I feel like it should be option A. The insert adds 10 at the end.
MY
My
9 months ago
I think it outputs 0 1 2 3 4 5 6 7 8 9.
HU
Hubert
9 months ago
No compilation errors here!
FR
Franklyn
10 months ago
I disagree, it should show 10 at the start.
RO
Rocco
10 months ago
Wait, I thought it would include the 10!
SH
Shawana
10 months ago
It outputs 0 1 2 3 4 5 6 7 8 9.
SK
Skye
10 months ago
The program compiles fine.
JE
Jeffrey
10 months ago
Wait, is this a trick question? I'm going to go with option B, just to be safe.
JE
Jessenia
11 months ago
Haha, the code looks like it was written by a monkey. I bet the correct answer is C, just to mess with us.
MA
Marjory
11 months ago
D. There must be a compilation error because the deque header is not included.
KI
Kip
11 months ago
I’m leaning towards option C because I think the insert doesn’t affect the output of d1, but I could be wrong.
CA
Catalina
11 months ago
I feel like the insert operation adds 10 to the front of the deque, so maybe it will print 10 first? But I’m not confident about that.
MI
Misty
11 months ago
The program should output 0 1 2 3 4 5 6 7 8 9 10, so the correct answer is A.
CE
Ceola
11 months ago
I remember a similar question where we had to deal with vectors and deques. I think the output might include the number 10 at the beginning, but I can't recall exactly.
EL
Elli
12 months ago
I think the correct answer is B. The insert method adds the element to the beginning of the deque.
MA
Marylin
1 year ago
I think the code should compile fine since all the included libraries are correct. But I'm not sure about the output after the insert operation.
DE
Dewitt
1 year ago
This looks straightforward to me. The insert() function on the deque is inserting the value 10 at the end of d1, so the output should be B.
KA
Kate
1 year ago
I'm not too sure about this one. I'll need to walk through the code step-by-step to figure out what's happening. Hopefully I can eliminate some of the options and make an educated guess.
VE
Vernell
1 year ago
Okay, I think I've got this. The key is that we're copying the deque d1 into d2, and then inserting an element at the end of d1 using the reverse iterator. So the output should be B.
CO
Coleen
1 year ago
Hmm, I'm a bit confused by the insert() function on the deque. I'll need to double-check the documentation to make sure I understand how that works.
TO
Tomoko
1 year ago
This looks like a tricky one. I'll need to carefully read through the code and think about how the deque and vector operations work.
GL
Gladys
8 months ago
I’m leaning towards option B.
MA
Margarita
8 months ago
So, is it option A or B then?
HE
Heidy
8 months ago
That changes the order, right?
CA
Carma
12 months ago
Yeah, but what about the insertion of 10?
ON
Oneida
1 year ago
I think it outputs the original vector first.