what happens if we delete a pointer twice..??

The results are undefined, which means that a program that does so is permitted to do anything at all.

what happens if we delete a pointer twice..??

The FBI, CIA, and the military comes to your house via dragon and breaths fire onto your soul sending you to hell for eternity to burn, simply because you deleted a pointer twice. So next time be aware.

The FBI, CIA, and the military comes to your house via dragon and breaths fire onto your soul sending you to hell for eternity to burn, simply because you deleted a pointer twice. So next time be aware.

And don't forget Basement Cat!

To give a more useful answer, that is, knowing what typically could happen when you delete a pointer twice might help you recognize the situation if you see those symptoms.

So, although it is undefined behaviour, as arkoenig mentioned, there are a number of things that would typically happen if you delete a pointer a second time, but it is, of course dependent on the implementation and the circumstances:
1) Nothing at all. It goes unnoticed and doesn't have a visible effect.
2) Heap corruption. The heap is asked to free a chunk of memory that is already freed or already allocated to something else, and because the heap is essentially a data-structure that does book-keeping of the free and allocated memory chunks, but at the same time, the heap typically cannot bare to do too much verification of the integrity of the requested allocation/deallocation, the result of deleting a pointer a second time can easily result in the heap being corrupted (i.e. it screws up the heap's book-keeping).
3) Crash. If the heap can verify that the pointer is already freed, or if the pointer happens to now be pointing outside the virtual address space of the program, the program will crash on either an access violation (seg. fault) or just a plain "abnormal termination".

If you see these symptoms or alternation between them (like changing something small in the code makes you jump from one symptom to the other), then you can suspect a double deletion of a pointer, amongst other nasty things. As you can guess, if you have such a bug, it is not easy to find or diagnose (even with tools like Valgrind), and it will often cause you a world of trouble to debug, so firstPerson's description of what happens is not so different from reality, eternal damnation awaits if you delete a pointer twice.

thank you mike... that was helpful..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.