Wednesday, 3 July 2013

what is dangling pointer | dangling pointer in c++

suppose we allocate a chunk of memory and store its address in a pointer. if this chunk of memory is freed and if the pointer continues to point  to the location, the pointer is sadi to be a dangling pointer is said to be a dangaling pointer;
For Example :

 #include <iostream>

void main()
{

     int *P;
       
     int *Q = new int;
   
    P = Q;
    delete  Q
}    

In this example p and Q are pointing to the same location in the memory. The statement delete q would free the allocated memory making p a dangling pointer;

      

0 comments:

Post a Comment