What is a Dangling Pointer? This has often been asked by my students. Here comes the answer.

A dangling pointer is one that points to an object that has already been deleted. As an example, let p1 and p2 be two pointers that are pointing to an object obj. If we delete one of these pointers, say, p1, the other pointer p2 becomes dangling. The following example would illustrate this better.

test *p1 = new test();

test *p2 = p1; //Now p1 and p2 both point to the same object.

delete p2;

p1->display(); //The pointer p1 is dangling!