The value after the delete pointer is null.

Source: Internet
Author: User

First, the C ++ standard stipulates that the delete NULL pointer is legal and has no side effects.
However, after the Delete P operation, only the memory space pointed to by the pointer is released. P is not automatically set to null, And the pointer is still pointing to the previous address.

The problem arises. After a non-null pointer is deleted, if null is not assigned and the delete operation is performed again, the problem may occur.
The following code

Int * P = new int (3); Delete P;


Problems may occur when compiled and run with VC.
Change it:

Int * P = new int (3); Delete P; P = NULL; Delete P;


No problem occurs (because the delete NULL pointer is legal)
Therefore, to avoid problems, the pointer should be assigned null after being deleted.

The value after the delete pointer is null.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.