NULL pointer is the same as deallocating it?

前端 未结 11 2542
一个人的身影
一个人的身影 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:52

    As per Phil Nash's comment, for every new, there is a corresponding delete, likewise, for every malloc, there is a corresponding free. If the corresponding delete/free is not there, you have a leak.

    Hope this helps, Best regards, Tom.

提交回复
热议问题