New Year Sale 2026! 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
Teri
4 days 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
9 days ago
Haha, "orez"? Really? That's just silly. The correct answer is clearly D) program outputs: five.
upvoted 0 times
...
Ira
14 days 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
19 days 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
25 days 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
30 days 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
1 month 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
1 month 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
2 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
2 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
2 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
2 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