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 7 Question 128 Discussion

Posted by Trinidad on Aug 16, 2026 at 04:34 PM

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

#include

#include

#include

#include

#include

using namespace std;

int main() {

int t[] = { 3, 4, 2, 1, 0, 3, 4, 1, 2, 0 };

vector v(t, t + 10);

multimap m;

for (vector::iterator i = v.begin(); i != v.end(); i++) {

stringstream s;s << *i << *i;

m.insert(pair(*i, s.str()));

}

pair::iterator, multimap::iterator> range;

range = m.equal_range(2);

for (multimap::iterator i = range.first; i != range.second; i++) {

cout << i?>first << " ";

}

return 0;

}

The output will be:

Suggested Answer: A

Get Premium CPP Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
13 comments · newest first
BA
Barney 8 hours ago
No way, it has to be A. The loop inserts 2 twice.
TR
Truman 5 days ago
But what about option D? Just 2?
ED
Edda 11 days ago
I feel like it should be option A too.
CA
Carmen 16 days ago
I think it will output 2 2.
DA
Dalene 21 days ago
The stringstream part is clever!
JE
Jerlene 26 days ago
I thought it would be "1 2" instead.
ME
Melinda 1 month ago
Wait, how does it get "2 2"?
KA
Katina 1 month ago
Definitely outputs "2 2".
AD
Adelaide 1 month ago
The code compiles without errors.
ER
Ernie 2 months ago
I believe the output should be just "2" since that's the only key that matches in the multimap, but I might be mixing it up with another question we did.
OL
Olive 2 months ago
I’m a bit confused about the `stringstream` part. Does it actually concatenate the number twice? I feel like that might affect what gets stored in the multimap.
LO
Louis 2 months ago
I remember something similar from practice where we used `equal_range` with a multimap. I think it should return all entries with the key 2, but I can't recall what those entries were.
KA
Katie 2 months ago
I think the code will compile fine, but I'm not sure about the output. It seems like it should print the values associated with the key 2.
0/2000 characters

Save Cancel