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 8 Question 101 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 101
Topic #: 8
[All CPP Questions]

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

template

void print(T start, T end) {

while (start != end) {

std::cout << *start << " "; start++;

}

}

int main()

{

int t1[] ={ 1, 7, 8, 4, 5 };

list l1(t1, t1 + 5);

int t2[] ={ 3, 2, 6, 9, 0 };

list l2(t2, t2 + 5);

l1.sort();

list::iterator it = l2.begin();

it++; it++;

l1.splice(l1.end(),l2, it, l2.end());

print(l1.begin(), l1.end()); cout<<"Size:"<

print(l2.begin(), l2.end()); cout<<"Size:"<

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Rosina
20 days ago
Wait, did they just throw a bunch of random numbers into a list and expect us to make sense of it? Sounds like a typical programmer's idea of a good time.
upvoted 0 times
...
Hubert
22 days ago
D, definitely D. That's my final answer, and I'm sticking to it like a piece of chewing gum on the underside of a desk.
upvoted 0 times
...
Bulah
23 days ago
Hmm, I'm not sure about this one. Maybe I should've paid more attention in that C++ class instead of doodling unicorns in my notebook.
upvoted 0 times
Trinidad
2 days ago
User1: Don't worry, let's try to figure it out together.
upvoted 0 times
...
...
Kina
27 days ago
Haha, I'm gonna go with B. Who needs to sort lists when you can just randomly rearrange them?
upvoted 0 times
Herman
24 hours ago
User3: I agree, just randomly rearrange them!
upvoted 0 times
...
Ora
19 days ago
User2: Yeah, who needs to sort lists anyway?
upvoted 0 times
...
Shawn
20 days ago
User1: I think the program outputs: 3 4 5
upvoted 0 times
...
...
Veronika
1 months ago
The correct answer is C. The code sorts the first list, then splices the elements from the second list starting from the third element (index 2) to the end of the second list, and appends them to the end of the first list. This results in the output: 1 3 4 5.
upvoted 0 times
Daniel
7 days ago
B) program outputs: 3 4 5
upvoted 0 times
...
Altha
15 days ago
A) program outputs: 1 2 4 5
upvoted 0 times
...
...
Jessenia
2 months ago
Hmm, I see your point. Let's wait for more opinions before deciding.
upvoted 0 times
...
Lizette
2 months ago
I disagree, I believe the answer is C) program outputs: 1 3 4 5.
upvoted 0 times
...
Jessenia
2 months ago
I think the answer is A) program outputs: 1 2 4 5.
upvoted 0 times
...

Save Cancel