Wisdom Podcast Video Learning---->>>> wild pointer causes and avoidance methods

Source: Internet
Author: User

The reason why the wild pointer is produced:

1, the pointer variable and the memory space variable that he points to are two different concepts

2, although the call to the free (p) method frees the memory space pointed to by the pointer, but the pointer variable is not reset to null

3, resulting in the freed of the pointed memory space, the use if (p! = NULL) is also executed, and the free () method is executed

Avoidance methods:

1, when the pointer is defined, initializes its value to null (char *p = null;)

2, after releasing the memory space pointed to by the pointer, reset the pointer to NULL

   

1     ······ 2 3 char *p = NULL; 4 5     ······ 6 7 if (P! = NULL) {  8free    (p); 9     p = NULL;            Ten }     

Wisdom Podcast Video Learning---->>>> wild pointer Generation and avoidance methods

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.