I know the addr#1 and addr#2 would print the same address. But is any way can identified a address that it is free to use?
Not easily or portably. This is specific to the behaviour of the C runtime library, so depends entirely on implementation details. Furthermore, this is undefined behaviour (use-after-free).
For example, you would need to use a heap checking routine such as mprobe
with GCC to query the state at runtime.
Somebody said it's not possible unless you reassign NULL or nullptr to addr to identify that.
No, that only changes your perspective on the use or state of that particular memory. It says nothing about the state of the system according to the runtime library which actually owns and manages this info.
Ok, so if the pointer is pointed to an object, and that object is deleted, the result was the same?
Yes, whether a pointer to an object or a pointer to a POD (as in your example), the result would be the same.
Conventional wisdom says that if you follow certain rules and best practices to do with memory management, you should never to worry about this sort of problem.
This whole question is a great motivating example for the use of smart pointers! Then the whole problem goes away.