In the following code I try to deallocate the memory for the Array and it only sets the first integer in the array to 0 and leaves the rest as it is. Is this supposed to happen if anyone knows? Thanks
Try to initialize the array size to 0 before you get user input. When I ran your code, after I deleted the array I just had the address of where the array was as output?
Just to clarify, when you delete something, it does not zero the memory, or do anything special. All it does is tell the OS "I'm done with this", so when you access the memory after you have deleted it, you could get valid numbers, garbage data, or maybe even a segfault (however unlikely).
Does you mean that delete[] only makes memory available to be over-written? Isn't that analogous to the way DOS deletes a file by only deleting its directory entry but not the file itself?
If so, then lines 31 and 23 of krahl's program should always give the same output, shouldn't it, because there is nothing between the delete command and the cout command to over-write the memory where ipArray is located?
So is ipArray called a dangling pointer or something after I delete it? for the reasons firedraco stated about accessing the memory after I delete it.
So infact if I had ran a larger program which accesses the memory more then I could get awkward numbers in the last for loop rather than 0, 2, and 3 for the size 3 array with original entries 1,2 and 3.
Am I right with this?
to fix the dangling pointer could I just put it to point to 0 or NULL?