In the code below, the value that the iterator points to is the same for both the last and the second last element.
#include <iostream>
#include <set>
using namespace std;
int main()
{
set<int> s1 = {4,3,2,5,1};
set<int>::iterator i;
i = s1.end();
cout << *i << endl; // 5
i--;
cout << *i << endl; // 5
cout << *s1.end() << endl; // 5
cout << *(--s1.end()) << endl; // 5
return 0;
}
In my understanding the value pointed to by the end element should be null. Why is this so?