Last Updated : 10 Apr, 2024
multimap<int, int> multp;
multp.insert(pair <int, int> (1, 40)); 
multp.insert(pair <int, int> (2, 30)); 
multp.insert(pair <int, int> (3, 60)); 
multp.insert(pair <int, int> (4, 20)); 
multp.insert(pair <int, int> (5, 50)); 
multp.insert(pair <int, int> (6, 50));  
multp.insert(pair <int, int> (6, 10)); 
  
multimap<int, int> :: iterator itr;
    
for(itr = multp.begin(); itr != multp.end(); itr++)
   cout << itr->first << \"-\" << itr->second << endl;

Possible outcome for the above code snippet
(A) 1-40
2-30
3-60
4-20
5-50
6-50
6-10
(B) 1-40
2-30
3-60
4-20
5-50
6-50
(C) 6-10
6-50
5-50
4-20
3-60
2-30
1-40
(D) None of these


Answer: (A)

Explanation: Multimap is similar to mapwith an addition that multiple elements can have same keys. Rather than each element being unique, the key value and mapped value pair has to be unique in this case.


Share your thoughts in the comments