Difference between dangling pointer and memory leak

后端 未结 8 1978
既然无缘
既然无缘 2020-12-12 08:44

I don\'t understand the difference between a dangling pointer and a memory leak. How are these two terms related?

8条回答
  •  臣服心动
    2020-12-12 09:18

    A pointer pointing to a memory location that has been deleted (or freed) is called dangling pointer.

    #include 
    #include  
     void  main()
     {
        int *ptr = (int *)malloc(sizeof(int));
        // After below free call, ptr becomes a 
        // dangling pointer
        free(ptr); 
     }
    

    for more information click HERE

提交回复
热议问题