🎙 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 5 of 9

What does this print? (code)

What does this print?

#include <iostream>
#include <set>
using namespace std;
int main() {
    set<int> s = {5, 1, 5, 3, 1};
    s.insert(3);
    cout << s.size() << " " << *s.begin() << "\n";
    return 0;
}
  1. A.6 5
  2. B.4 1
  3. C.3 1
  4. D.3 5
Answer & explanation

Correct answer: 3 1

A set keeps only unique values in sorted order: {1, 3, 5}, so the size is 3 and the first is 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 →