map stl Question 10

Last Updated :
Discuss
Comments

What will be the output of the following C++ program?

#include <bits/stdc++.h>
using namespace std;
int main()
{

multimap<int, int> mp;

mp.insert({ 2, 30 });
mp.insert({ 1, 40 });
mp.insert({ 3, 60 });
mp.insert({ 1, 20 });
mp.insert({ 5, 50 });

auto it = mp.equal_range(1);


for (auto itr = it.first; itr != it.second; ++itr) {
 cout << itr->first
  << '\t' << itr->second << '\n';
}
return 0;
}

1 40
1 20
 

3 60
1 20
 

1 40
2 30
 

3 60
5 50
 

Share your thoughts in the comments