What happens to an address after delete operator has been applied to it in C++?

前端 未结 5 599
春和景丽
春和景丽 2020-12-19 09:51

If I delete a pointer as follows for example:

delete myPointer;

And, after that did not assign 0

5条回答
  •  -上瘾入骨i
    2020-12-19 10:37

    No, in most implementations it will store the same address as previously - delete usually doesn't change the address and unless you assign a new address value it remains unchanged. However this is not always guaranteed.

    Don't forget, that doing anything except assigning a null pointer or another valid pointer to an already deleted pointer is undefined behavior - your program might crash or misbehave otherwise.

提交回复
热议问题