Stl lower bound in set

In this question, auto it gets the value 6, which is beyond the set index, then *it should return a garbage value right?
But the answer is 6, can you explain this?

hello @niveditha_palli

in the case when the element being searched is greater than the maximum element in set the returned value (st.end()) is number of elements in the set which in this case is 6.

So it gets value 6, but how is *it is 6?

in above case we get iterator st.end() whose value ( i.e *st.end() ) is six.

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.