What will be printed to the console?
#include <iostream>
#include <map>
int main(void)
{
    std::map<int, int> dict;
    dict[0]=10;
    if(dict[0]!=dict[1])
        dict[2]=100;
    std::cout << dict.size();
    return 0;
}
Explanation
When accessing an element of the map container by key in the case when such a key is missing, it is automatically added with a default value. Based on the example, the value 10 is put in dict[0]. Next, the value 0 will be put in dict[1]. When checking 10 != 0, and the value 100 will be put into dict[2]. As a result, the container will contain 3 elements.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes