Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

null pointer vs dangling pointer

Is there a meaningful difference between a null pointer and a dangling pointer? It seems like these are both terms used for pointers that don't point to anything. Is the idea that a dangling pointer used to refer to something and now doesn't -- where a null pointer is just a pointer that does not refer to anything (regardless of what it pointed to in the past)?

like image 764
bernie2436 Avatar asked Oct 03 '12 18:10

bernie2436


1 Answers

Pointer terminology:

  • Dangling (or wild) pointer: a pointer that points somewhere, but not to a valid object.
  • Null pointer: a pointer that points to a specially designated out-of-bounds location that programs will never legally store data in. Special class of dangling pointer.
  • Uninitialized pointer: a pointer that was never assigned to the address of something. A type of dangling pointer.
  • Stale pointer: a pointer that used to point to something, but the target has been deleted (either via delete operator, free, or gone out of scope). A type of dangling pointer.

Pointers that are dangling can be said to be pointing to Hyperspace or to Another Dimension, except the null pointer, which is generally referred to as pointing to Nothing.

like image 87
Wug Avatar answered Oct 09 '22 15:10

Wug