Set.insert return value

In this question, is the output 0 because by default ret.second i.e., the initialized value of bool is 0?

hello @niveditha_palli

pls share the question with me.

It’s question 13 : What will be the output of following C++ code? #include <bits/stdc++.h> using namespace std; int main() { sets; pair<set::iterator, bool> ret; s.insert(1); s.insert(5); s.insert(10); s.insert(3); ret = s.insert(10); cout<<ret.second<<endl; return 0; }

@niveditha_palli

insert returns a pair.
here is the detail->
a pair with its member pair::first set to an iterator pointing to either the newly inserted element or to the equivalent element already in the set. The pair::second element in the pair is set to true if a new element was inserted or false if an equivalent element already existed.

output is 0 because 10 was already there in the set

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.