Why is answer 6?

lower_bound(15) it should be something >=15 but no element is greater than 15,so it points to end.Hence some garbagge vallue

@alampallyvinith
hello vinith,
lower_bound(x) return the iteratior of array element which staisties <= property.

please send the question so that i can help u furthur,

@aman212yadav
Hello aman,
lower_bound(x) gives iterator to something>=x,not <=x according to the lecture

@alampallyvinith
yeah i am saying the same thing.

<= (this we read as greater than equal to right?)

‘<=’ is less than equal to

ok then it should be >=

@aman212yadav
Now this is the code

#include
#include
#include
using namespace std;
int main()
{
sets;
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;
}

answer my actual query

@alampallyvinith

in this case ur lower bound will return s.end() and i think value of s.end() is number of elements stored in the set . In ur case there are total six elements stored in set that why getting 6 as the value

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.