is it same as wild pointer?please provide a eg to understand this.
What is dangling ponter?
Hi Aman,
Dangling Pointer: A pointer pointing to a memory location that has been deleted (or freed) is called dangling pointer. A dangling pointer points to data which is not valid anymore,
Ex:
Class *object = new Class();
Class *object2 = object;
delete object;
object = nullptr;
// now object2 points to something which is not valid anymore
Wild Pointer: A pointer which has not been initialized to anything (not even NULL) is known as wild pointer. The pointer may be initialized to a non-NULL garbage value that may not be a valid address.
Ex:
int main()
{
int *p; // wild pointer
int x = 10;
// p is not a wild pointer now
p = &x;
return 0;
}