Cyber Monday 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
2 months 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
Pearly
29 days ago
User3: Yeah, the options are a bit tricky with the string values included
upvoted 0 times
...
Lachelle
1 months ago
No, I believe it will be 1 1 2 2 3 4 4 5 5
upvoted 0 times
...
Luisa
1 months ago
I think the output will be 1 2 4 5
upvoted 0 times
...
...
Kris
2 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
1 months ago
I'm pretty sure it's A.
upvoted 0 times
...
Rosendo
1 months ago
No, I believe the answer is D.
upvoted 0 times
...
Arlen
2 months ago
I think the answer is B.
upvoted 0 times
...
...
Gail
3 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
1 months ago
I agree, the output will be 1 2 3 4 5. Tricky, but not that tricky.
upvoted 0 times
...
Hoa
2 months ago
Yeah, that erase(3) is a red herring. The answer is definitely A.
upvoted 0 times
...
Hoa
2 months ago
A) program outputs: 1 2 3 4 5
upvoted 0 times
...
...
Denny
3 months ago
I'm not sure, but I think the program will output: 1 2 4 5.
upvoted 0 times
...
Oneida
3 months ago
I believe the answer is D.
upvoted 0 times
...
Charlena
3 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
2 months ago
E) program outputs: one two three four five
upvoted 0 times
...
Carrol
2 months ago
D) program outputs: 1 1 2 2 4 4 5 5
upvoted 0 times
...
Alex
2 months ago
C) program outputs: 1 1 2 2 3 4 4 5 5
upvoted 0 times
...
Tawna
2 months ago
B) program outputs: 1 2 4 5
upvoted 0 times
...
Latonia
2 months ago
A) program outputs: 1 2 3 4 5
upvoted 0 times
...
...
Denny
3 months ago
I think the answer is B.
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