Dangling pointers can be better explained using the following example.
int * function()
{
int A[5] = {1, 2, 3, 4, 5};
return(A);
}
int main() {
int *array = function();
for (int i=0;i<5;i++)
printf("%d",array[i[);
}
Even though, the program may appear as perfect, it has a bug. Since
the allocation remains active only during the execution of the
function ( ). After retruning from the function, the array gets
deallocated. So printing the values inside the main () prints garbage
values. These are what u call it as DANGLING pointers.
--
SeNtHiL rAj,