C++ Institute CPP Exam - Topic 9 Question 97 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);dequed1;d1.assign(v1.end(), v1.begin());for(int i=0; i
C) compilation error in line 8
A) program outputs 5 4 3 2 1
B) program outputs 1 2 3 4 5
D) compilation error in line 10
E) segmentation fault runtime exception
C++ Institute CPP Exam - Topic 9 Question 97 Discussion
I'm pretty confident that the answer is A. The `assign()` function on the `deque` will copy the elements from the `vector` in reverse order, so the output should be 5 4 3 2 1.
Alright, let me walk through this step-by-step. The `vector` is initialized with the values 1, 2, 3, 4, 5. Then, the `deque` is assigned the elements of the `vector` in reverse order. So, I think the output will be 5 4 3 2 1.
Okay, let me see here. The code is trying to assign the elements of the `vector` to the `deque` in reverse order. I think the answer might be A, but I'm not 100% sure.
Hmm, this looks like a tricky one. I'll need to carefully read through the code and think about the behavior of the `deque` and `vector` data structures.
I'm a bit confused by the `assign()` function call on the `deque`. I'll need to double-check the documentation to make sure I understand how that works.
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.
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!
Francesco
10 months agoYolande
10 months agoAlexis
11 months agoTasia
11 months agoElli
11 months agoCarey
11 months agoRozella
12 months agoGerald
12 months agoHelga
12 months agoElden
12 months agoFranchesca
12 months agoBok
12 months agoIlda
12 months agoAnnita
1 year agoPaulina
1 year agoBrittani
1 year agoClement
1 year agoPaz
1 year agoLeatha
1 year agoShenika
1 year agoDiane
1 year agoLorriane
1 year agoTaryn
1 year agoRoosevelt
1 year agoCoral
1 year agoStevie
1 year agoAlishia
1 year agoGeorgeanna
1 year agoNida
1 year agoIndia
2 years agoRessie
2 years agoIndia
2 years ago