R
Randy Gordon
Say I do the following:
char **names = new char*[100];
for (int i = 0; i < 100; i++) {
names = new char[5];
}
When I'm done with the array of character pointers, how should I delete it?
Like this:
for (int i = 0; i < 100; i++) {
delete names;
}
delete[] names;
or like this:
delete[] names;
Basically, does delete[] call each individual delete or not? If so, what
happens if I do the former method? Assuming it doesn't, then I guess the
second method would create a memory leak.
char **names = new char*[100];
for (int i = 0; i < 100; i++) {
names = new char[5];
}
When I'm done with the array of character pointers, how should I delete it?
Like this:
for (int i = 0; i < 100; i++) {
delete names;
}
delete[] names;
or like this:
delete[] names;
Basically, does delete[] call each individual delete or not? If so, what
happens if I do the former method? Assuming it doesn't, then I guess the
second method would create a memory leak.