I have a vector storing {1,2,3,4,5}. I tried to print *(vec.end()) and got back the result 6. I don\'t know how to explain this. Similarly, calling vec.fi
*(vec.end())
vec.fi
This line invokes undefined behavior:
std::cout << *(set1.end()) << std::endl;
It is undefined behavior to dereference the end() iterator. Thus anything can be expected.
end()