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 CPP Exam - Topic 9 Question 117 Discussion

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

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

#include

#include

#include

#include

using namespace std;

template

void print(T start, T end)

{

while (start != end)

cout<<*start++;

}

int main ()

{

string t[] = {"one", "two" ,"three" ,"four", "five"};

vectorv1(t, t+5);

dequed1(v1.rbegin(), v1.rend());

d1.push_back("zero");

print(d1[0].rbegin(),d1[0].rend());

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

0/2000 characters
Leslee
2 days ago
Not sure about that output... seems off.
upvoted 0 times
...
Glenna
7 days ago
Totally agree with Glendora on this one!
upvoted 0 times
...
Lottie
12 days ago
Wait, does it really compile without errors?
upvoted 0 times
...
Daryl
18 days ago
I think it should output "five".
upvoted 0 times
...
Glendora
23 days ago
The output will be "orez".
upvoted 0 times
...
Ilene
28 days ago
Ah, the old "reverse a string" trick. Classic programming question. D) program outputs: five is the way to go here.
upvoted 0 times
...
Teri
2 months ago
Wait, what? Printing the reverse of a string? That's just plain weird. I'm going with C) compilation error.
upvoted 0 times
...
Ryan
2 months ago
Haha, "orez"? Really? That's just silly. The correct answer is clearly D) program outputs: five.
upvoted 0 times
...
Ira
2 months ago
I'm pretty sure this will result in a compilation error. The `print()` function is expecting an iterator, but we're passing in a reverse iterator.
upvoted 0 times
...
Dulce
2 months ago
The program should output "evif" since we're printing the reverse of the string "five" which is the last element in the deque.
upvoted 0 times
...
Lashon
2 months ago
I’m a bit confused about the print function. It looks like it’s trying to print characters in reverse, but I’m not sure if that will work as expected.
upvoted 0 times
...
Venita
2 months ago
This reminds me of a practice question where we had to reverse a vector. I feel like the output might be "five" since it's the last element added.
upvoted 0 times
...
Alonzo
3 months ago
I remember something about iterators and how they work with containers, but I can't recall if using rbegin() and rend() on a string is valid.
upvoted 0 times
...
Johanna
3 months ago
I think the code should compile fine since all the includes seem correct, but I'm not sure about the output.
upvoted 0 times
...
Genevive
3 months ago
Okay, I think I've got it. The deque is initialized with the vector elements in reverse order, then "zero" is added to the back. So the print function will display the last element, which is "zero" in reverse, giving the output "evif".
upvoted 0 times
...
Portia
3 months ago
Hmm, I'm not sure about this one. The code looks a bit complex with all the container types and iterator usage. I'll have to think it through carefully to determine the correct output.
upvoted 0 times
...
Layla
3 months ago
I'm a bit confused by the use of the reverse iterators in the print function. Is that necessary for the output we're expecting?
upvoted 0 times
...
Aliza
4 months ago
I think the correct answer is D. The program should output "five" since we're printing the last element of the deque, which is "zero" in reverse.
upvoted 0 times
...

Save Cancel