Say you have a function like:
void foo()
{
char* pt = new char[10];
//do stuff with pt
}
Since the pointer was created locally, will the memory be freed once the function terminates? Or do you really need to use delete[]
to free the memory?
Memory allocated with new
/new[]
have dynamic storage duration. They are not deallocated until the user explicitly calls delete
/delete[]
.