c++ - about the vector.push_back -


i wrote program follows:

if(i = 0) {   vector<int> data;     vector<int>::iterator it;     data.push_back(2);     data.push_back(3);     sort(data.begin(),data.end());     = data.begin(); }  if(i = 0) {   vector<int> data;     vector<int>::iterator it;     data.push_back(5);     data.push_back(1);     sort(data.begin(),data.end());     = data.begin(); } 

if use vector<int> 2 times, release automatically? should release memory?

memory allocation local variables deleted automatically when variable goes out of scope.

if(i == 0) {     std::vector<int> data; //local variable } //allocation 'data' deleted automatically if(i == 0) {     std::vector<int> data; //this not same vector above     //in fact, vector above no longer exists @ point } //allocation 'data' deleted automatically 

Comments