11-05-2011, 05:13 PM
A dangling pointer is a pointer which has been allocated but does not point to any entity. For example un-initialized pointer.
int * ptr;
*ptr = 10;
The correct way of doing so is:
int * ptr;
int a;
ptr = &a;
*ptr = 10;
Another example can be a function returning reference of a local variable. The local variables are destroyed when function call ends, so if you try to access that location which has been deleted, it may lead you to unpredictable results.
int * ptr;
*ptr = 10;
The correct way of doing so is:
int * ptr;
int a;
ptr = &a;
*ptr = 10;
Another example can be a function returning reference of a local variable. The local variables are destroyed when function call ends, so if you try to access that location which has been deleted, it may lead you to unpredictable results.
Code:
int * function()
{
int a = 10;
return &a;
}
int* ptr = function();
*ptr = 5;0300-9520262
Get solution in 24 hour |cpmputer & internet
mileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
