Does 'delete [] varname;' delete multiple arrays in C++?

  • Context: C/C++ 
  • Thread starter Thread starter neurocomp2003
  • Start date Start date
  • Tags Tags
    Arrays
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 6K views
neurocomp2003
Messages
1,359
Reaction score
4
Was wondering if the "delete [] varname;" deletes multiple arrays

eg...

I coded a 3-D array as follows:

type ***name;
name = new type**[n];
for i: name= new type*[n];
for i,j: name[j]=new type[n];
and name[j][k] is and element in the array

now does
"delete [] varname;" suffice to delete the 3D array?
or do i have to first delete name[j] then delete name and then name.
 
Physics news on Phys.org
coo, thanks so its

for i,j: delte name[j]
for i: delete name
delete [] name?

oh yeah one other Q, if i allocate memory and forget to deallocate...when the programm shuts down does it autodeallocate for me? or do i have to turn off my system?
 
Yes, that works, just spell delete correctly.

Yes it will free the memory, but don't rely on it. That is bad programming because while you run the program you'll be wasting a lot of memory.
 
thanks dduardo...heh i was just using "delete [] name" now i should go correct it. Its fun to watch 1000 3D spherical (billiard) balls colliding eating up the resources, yay for a double for loop...now i got to add in some scene mgmt tech.