Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <map>
using namespace std;
int main ()
{
    map<char, int> mymap;
    map<char, int> :: iterator it;
    mymap['b'] = 100;
    mymap['a'] = 200;
    mymap['c'] = 300;
    for (map<char, int> :: iterator it = mymap.begin(); it != mymap.end(); ++it)
        cout << it -> first << " => " << it -> second << '\n';
    return 0;
}

A. a => 200
c => 300

B. a => 200
b => 100

C. a => 200
b => 100
c => 300

D. a => 200

Answer: Option C


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it