top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is a wild pointer and why is it necessary to get rid of it?

+5 votes
331 views
What is a wild pointer and why is it necessary to get rid of it?
posted Mar 25, 2016 by Shahsikant Dwivedi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
 
Best answer

A pointer pointing to a invalid memory location is known as wild pointer it is most of the cases occurs when we use an Uninitialized pointers or freed pointer, which may point to some arbitrary memory location and may cause a program to crash or behave badly.

See the following program which will explain -

int main()
{
  int *p;  /* Here P is wild pointer */
  *p = 12; /* Some unknown memory location is being corrupted and This should never be done. */
}

How to Avoid Wild Pointer
Following program would explain how to avoid WIld Pointer.

int main()
{
   int *p = malloc(sizeof(int));
  *p = 12; /* This is safe */
  free(p);
  p=NULL; /* we are marking P to NULL so that in rest of the program P is not used */
}
answer Mar 25, 2016 by Salil Agrawal
...