vendredi 13 août 2021

About iterator of containers

I do not know, why does it output 1024?

vector<int> default_container = { 1,2,3,4,5,6,7,78,8,1024 };
cout << *default_container.end() << endl; // 0
default_container.pop_back();

for (auto it : default_container) 
{
    cout << it << ",";
}
cout << endl;

cout << *default_container.end() << endl;   // 1024 why?why?why?why?
cout << *--default_container.end() << endl; // 8

Aucun commentaire:

Enregistrer un commentaire