Wild pointers
The pointers which are not initialized and are pointing to some random location are wild pointers. Pointers pointing to a known defined variable are not wild pointers but if it is pointing to a value or a set of values without value being assigned to a variable then pointer is referred to as wild pointer. Wild pointers causes a program to crash abruptly or program not behave properly as expected in short behave badly.
Example of Wild pointer:
int main()
{
/* wild pointer */
int *p;
/*assigning value to p makes it point to unknown memory location and location becomes corrupted. */
*p = 12;
}
Avoiding wild pointer:
int main()
{
int *p = malloc(sizeof(int));
*p = 12; /* This is fine (assuming malloc doesn't return NULL) */
}
0 Comment(s)