🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: STL Containers: all 9 questions

Quiz: STL Containers · Question 4 of 9

What does this print? (code)

What does this print?

#include <iostream>
#include <map>
using namespace std;
int main() {
    map<string, int> m;
    int x = m["missing"];
    cout << x << " " << m.size();
    return 0;
}
  1. A.Error
  2. B.0 1
  3. C.0 0
  4. D.-1 0
Answer & explanation

Correct answer: 0 1

m["missing"] inserts the key with value 0, so the size becomes 1.

Can you get the rest right without peeking?

Take the timed Quiz: STL Containers quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →