so i initialised array during runtime and then i used delete command and tried accessing array and i was able to access that array but some element got deleted and were valued to zero
here is link to my code : https://ide.codingblocks.com/s/80569
explain whats happening after using delete [ ] arr;
???
I am still able to access array after using delete [ ] arr explain plz
Deleting the array just makes the memory previously taken up by the array available for re-allocation and does not necessarily mean that the memory will be immediately overwritten by garbage or some other values.
but when i print array again then some elements are overwritten by 0 and some left unchanged …can u explain?
Hi Tarandeep
Kushal is right, delete just makes sure the range of the memory is unassigned internally, which means another call to new can use that same memory range. Then after that whatever data in that memory would be overwritten, arr[i] won’t return the same thing anymore. You are able to see other elements because those memory locations have not been overwritten by any other element, But they are available to be allocated.
If you won’t delete the array, memory will not be available for re-allocation.