Q : What is dangling pointer in C? What is wild pointer in C? Give example?
Dangling Pointer
Dangling or wild is a pointer which does not point
valid object. When a pointer has declared it must be assign a valid
address memory address otherwise it will point some location which is not
valid. These are special cases of memory safety violations.
More generally, dangling references and wild references are references that do not resolve to a valid destination.
Void main()
{
int *pt;
{
int
c=10;
pt=&c;
}
printf("\n\t%d",*pt);
}
Wild Pointer
As in above program c falls out of scope due to local
variable and there is an attempt to read C variable which is cleared from
memory.
A wild pointer also points an invalid memory address as in
following program. Arbitrary memory
location and may cause a program to crash or behave badly
void main()
{
int *pt;
*p=10;
printf("\n\t%d",*pt);
}
No comments:
Post a Comment