can u tell me the reson that why we should not delete a pointer twice.?
if we delete ponter twice then what happen and why this happen
Regards,
Amit
If you buy a car, can you you then sell it twice? No, because the 2nd time you no longer own it.
This is the same with memory, you allocate it, then release it. Once you have released the memory goes back into the free pool ready to be given out again.
If you release the pointer twice, then that memory may have been allocated between those two deletes to somebody else. You have then just freed some memory that another part of the code was trying to use.
In the words of the Fat Controller, you will cause chaos and confusion.
And may i add, if you just dive a little deeper into the malloc.c code (which i doubt you will
...)it will mark 'something' according to the structure you give as paramater to free(), if the memory has already been freed then it will 'access' some invalid memory and will inevitably segfault ...