Answer the question
In order to leave comments, you need to log in
Will memory be freed if we use the clear() method on a vector that has been filled with structures?
name = new char[20];
std::cin >> name;
data.push_back(Student{(short) data.size(),name});
data.clear();
struct Student
{
int id;
char *name;
};
Answer the question
In order to leave comments, you need to log in
name will not be released, there will be a memory leak.
If you need to free memory, then it is better to do Student as a class and, accordingly, create name in the constructor and release it in the destructor
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question