Dangling pointer

A pointer pointing to an object that has been destroyed is called a Dangling pointer.


main( )
{
int *p ;
int *fun( ) ;
p = fun( ) ;
printf ( "%d", *p ) ;
}

int *fun( )
{
int a = 10 ;
return ( &a ) ;
}
Here it appears that address of a would be collected in p and through *p we would be able to access 10. This however is not possible because by the time address of a is collected in p, a is already dead. So you have a pointer containing an address, and the object at this address is long dead. Thus p becomes dangling pointer.