How sets store data and why I am getting inappropriate output

Hello there everyone,
While I was implementing set I found a quite weird output, as sets store data in sorted order, I am passing greater sort. I inserted a few data and I got an output which was unexpected I am attaching that here

I have two question

  1. When my set size is 4 why fifth number is being printed “-3” in my case
  2. Do sets store all data in same address??? as the address of all data is same

I will be highly thankful if you can help me in solving my doubts!

Please post your full, formatted code - no one wants to squint at a PNG :slight_smile:

Without seeing your full code, it’s impossible to say - it doesn’t seem to be anything to do with the code you have shown, though.

You’re printing the address of the iterator, not the element in the set :slight_smile:


on the fifth line,replace >> by > >.This is because >> is an right shift operator in c++.this can create problems!!

it doesnt make a difference. @ashutosh_6500


Ok. Actually,set resembles binary search tree to add node at proper place.

  1. Where are you printing -3 ?? I can’t see a print statement.
  2. Set stores at different address. “it” itself is a pointer/iterator. You should print “it” to see the address of the set’s element. &it refers to the location of “it” in the memory which is always constant as it is a pointer/iterator,