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
In C++ containers, the end
iterator gives an iterator one past the end of the elements of the container. It's not safe to dereference the iterator because it's not actually looking at an element. You get undefined behavior if you try to do this - it might print something sensible, but it might just immediately crash the program.
Hope this helps!