I didnt understand how clear() works in the vector. when I perform vector.clear(); it still displays the elements of the vector but size becomes 0
code :
vector<int> a(5,10);
cout << "\nSize of vector a : " << a.size() << endl;
cout << "vector a : ";
for (int i=0; i<5; i++) {
cout << a[i] << " ";
}
a.clear();
cout << "\nSize of vector a after clear : " << a.size() << endl;
int is_empty = a.empty();
if (is_empty == 1) {
cout << "vector is empty." << endl;
}
cout << "vector a : ";
for (int i=0; i<5; i++) {
cout << a[i] << " ";
}
Output :
Size of vector a : 5
vector a : 10 10 10 10 10
Size of vector a after clear : 0
vector is empty.
vector a : 10 10 10 10 10