BlackFriday 2024! 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 94 Discussion

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

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

#include

#include

using namespace std;

int main() {

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

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

multimap m;

for (int i = 0; i < 10; i++) {

m.insert(pair(t[i], s[i]));

}

if (m.count(3) == 2) {

m.erase(3);

}

for (multimap::iterator i = m.begin(); i != m.end(); i++) {

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

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Rene
25 days ago
Wait, did they really put 'one two three four five' as an option? That's just the string values, not the actual output. Gotta be more careful with these tricky questions!
upvoted 0 times
Lachelle
13 days ago
No, I believe it will be 1 1 2 2 3 4 4 5 5
upvoted 0 times
...
Luisa
14 days ago
I think the output will be 1 2 4 5
upvoted 0 times
...
...
Kris
1 months ago
Oh man, I remember learning about multimaps in class. This looks like a standard multimap insertion and removal operation. The answer has to be B, right?
upvoted 0 times
Yen
9 days ago
I'm pretty sure it's A.
upvoted 0 times
...
Rosendo
13 days ago
No, I believe the answer is D.
upvoted 0 times
...
Arlen
22 days ago
I think the answer is B.
upvoted 0 times
...
...
Gail
2 months ago
Haha, looks like someone's trying to trick us with that 'erase(3)' call. But I bet the answer is still pretty straightforward if you know your multimap stuff.
upvoted 0 times
Hoa
14 days ago
I agree, the output will be 1 2 3 4 5. Tricky, but not that tricky.
upvoted 0 times
...
Hoa
26 days ago
Yeah, that erase(3) is a red herring. The answer is definitely A.
upvoted 0 times
...
Hoa
29 days ago
A) program outputs: 1 2 3 4 5
upvoted 0 times
...
...
Denny
2 months ago
I'm not sure, but I think the program will output: 1 2 4 5.
upvoted 0 times
...
Oneida
2 months ago
I believe the answer is D.
upvoted 0 times
...
Charlena
2 months ago
The program will output 1 2 4 5, as the question states that the 'erase(3)' call will remove the two occurrences of the key 3 from the multimap.
upvoted 0 times
Aliza
16 days ago
E) program outputs: one two three four five
upvoted 0 times
...
Carrol
20 days ago
D) program outputs: 1 1 2 2 4 4 5 5
upvoted 0 times
...
Alex
22 days ago
C) program outputs: 1 1 2 2 3 4 4 5 5
upvoted 0 times
...
Tawna
1 months ago
B) program outputs: 1 2 4 5
upvoted 0 times
...
Latonia
1 months ago
A) program outputs: 1 2 3 4 5
upvoted 0 times
...
...
Denny
2 months ago
I think the answer is B.
upvoted 0 times
...

Save Cancel