When you delete an object by pointer, two things happen:
Once you call delete b
you can reuse b
to point to another object, like this
b = new int(123);
or like this
int a(123);
b = &a; // Obviously, you can't delete b after this
or you can set it to nullptr
, like this
b = nullptr;
but you cannot dereference the pointer, because it would cause undefined behavior.
Does b remain a pointer pointing to the adress where the object created by new used to live?
Usually, that is exactly what happens - the value of b
remains unchanged. However, there is no standard-compliant way to find out, because C++ implementation is free to set it in whichever way it likes. For example, the pointer could be set to a trap representation, so merely printing the value of the pointer would cause a crash.