Pointer (computer Programming) - Wild Pointers

Wild Pointers

A wild pointer is a pointer that has not been initialized (that is, a wild pointer has not had any address assigned to it) and may make a program crash or behave oddly. In the Pascal or C programming languages, pointers that are not specifically initialized may point to unpredictable addresses in memory.

The following example code shows a wild pointer:

int func(void) { char *p1 = malloc(sizeof(char)); /* (undefined) value of some place on the heap */ char *p2; /* wild (uninitialized) pointer */ *p1 = 'a'; /* This is OK, assuming malloc has not returned NULL. */ *p2 = 'b'; /* This invokes undefined behavior */ }

Here, p2 may point to anywhere in memory, so performing the assignment *p2 = 'b' can corrupt an unknown area of memory or trigger a segmentation fault.

Read more about this topic:  Pointer (computer Programming)

Famous quotes containing the word wild:

    Ah! I have penetrated to those meadows on the morning of many a first spring day, jumping from hummock to hummock, from willow root to willow root, when the wild river valley and the woods were bathed in so pure and bright a light as would have waked the dead, if they had been slumbering in their graves, as some suppose. There needs no stronger proof of immortality. All things must live in such a light. O Death, where was thy sting? O Grave, where was thy victory, then?
    Henry David Thoreau (1817–1862)