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
1 months 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
1 months 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
1 months 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
Minna
14 days ago
User2: I think the program outputs: 1 3 4 5
upvoted 0 times
...
Trinidad
17 days ago
User1: Don't worry, let's try to figure it out together.
upvoted 0 times
...
...
Kina
1 months ago
Haha, I'm gonna go with B. Who needs to sort lists when you can just randomly rearrange them?
upvoted 0 times
Herman
16 days ago
User3: I agree, just randomly rearrange them!
upvoted 0 times
...
Ora
1 months ago
User2: Yeah, who needs to sort lists anyway?
upvoted 0 times
...
Shawn
1 months ago
User1: I think the program outputs: 3 4 5
upvoted 0 times
...
...
Veronika
2 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
Lavonna
8 days ago
C) program outputs: 1 3 4 5
upvoted 0 times
...
Daniel
22 days ago
B) program outputs: 3 4 5
upvoted 0 times
...
Altha
30 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
3 months ago
I think the answer is A) program outputs: 1 2 4 5.
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