STL Quiz lower_bound

Q7. stl lower_bound in set
What will be the output of the following C++ code?

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main()
{
    set<int>s;
    s.insert(1);
    s.insert(5);
    s.insert(7);
    s.insert(2);
    s.insert(12);
    s.insert(10);
    auto it = s.lower_bound(15);
    cout<< *it <<endl;
    return 0;
}

15

5

6

Any garbage value

My answer is Any garbage value

Answer must be 6
*s.end()= number of elements in the set.
In the case when the element being searched is greater than the maximum element the set the returned value is number of elements in the set which in this case is 6.

2 Likes

Okay. I dont know about that.