int main() { Employee *e = new Employee(); delete e; delete e; ... delete e; return 0; }
If delete is applied to one of the pointers, then the object's memory is returned to the free store. If we subsequently delete the second pointer, then the free store may be corrupted.
If we free the same pointer two or more time, then the behavior is undefined. So, if we free the same pointer which is freed already, the program will stop its execution.
No! (Assuming you didn't get that pointer back from new in between.)
The pointer itself does have an address and the value. The address of the pointer does not change after you perform delete on it. The space allocated to the pointer variable itself remains in place until your program releases it (which it might never do, e.g. when the pointer is in the static storage area).
You get undefined behaviour if you try to delete
an object through a pointer more than once.
This means that pretty much anything can happen from 'appearing to work' to 'crashing' or something completely random.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With