Last Updated : 10 Apr, 2024
unordered_set<int> us;
us.insert(2);
us.insert(3);
us.insert(4);
us.insert(5);
us.insert(2);
    
unordered_set<int> :: iterator itr;
for(itr = us.begin(); itr != us.end(); itr++)
  cout << *itr << \" \"; 

Predict the output for the above code snippet:
(A) 2 3 4 5 2
(B) 5 4 2 3
(C) 2 2 3 4 5
(D) 2 3 4 5


Answer: (B)

Explanation: unordered_set does not maintain order and does not allow duplicate keys as well

unordered_set unordered_set_name; 

is the syntax to create unordered_set



Share your thoughts in the comments