Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <map>
    using namespace std;
    int main ()
    {
    multimap<char, int> MultimapData;
    MultimapData.insert(make_pair('Q', 105));
    MultimapData.insert(make_pair('Q', 250));
    MultimapData.insert(make_pair('Q', 120));
    MultimapData.insert(make_pair('Q', 102));
    MultimapData.insert(make_pair('Q', 220));
    pair<char, int> highest = *MultimapData.rbegin();
    multimap<char, int> :: iterator Iter = MultimapData.begin();
    do
    {
    cout << (*Iter).first << " => " << (*Iter).second << '\n';
    } while ( MultimapData.value_comp()(*Iter++, highest) );
    return 0;
    }
    1. 105
    2. 250
    3. 120
    4. 102
    5. 220
Correct Option: A

In this program, the method rbegin is used to return the first element in the map.



Your comments will be displayed only after manual approval.