NULL pointer is the same as deallocating it?

前端 未结 11 2739
一个人的身影
一个人的身影 2021-02-18 18:29

I was working on a piece of code and I was attacked by a doubt: What happens to the memory allocated to a pointer if I assign NULL to that pointer?

For instance:

11条回答
  •  耶瑟儿~
    2021-02-18 18:58

    You need to delete A;

    For regular objects setting the pointer to NULL does nothing but invalidating the pointer, the object is still around in memory, this is particularly true if you notice that you may have more than one pointer to the same object, changing one shouldn't affect the others.

提交回复
热议问题