Masih (4th June 2007)
Yes, this is the best analogy so far.
A pointer is just like a normal variable, but it's contents, instead of a value that you can normally use in your program, are a memory address of, let's say another variable.
If the memory at that address has been deallocated, then your pointer still exists, but it does not point to anything( anything valid ).
So it is no magic going on here. It's a about understanding what a pointer really is.
Regards
Masih (4th June 2007)
I've recently seen another explanation from this book : " An introduction to design patterns in C++ with Qt4" by Ezust & Ezust .
Wanted to post it here
Zero (0), often represented by the macro NULL in C programs, is a special value that can be legally assigned to a pointer, usually when it is being initialized (or re-initialized). 0 is not the address of any object. A pointer that stores the value 0 is called a null pointer. Stroustrup recommends the use of 0 rather than the macro NULL in C++ programs.
Bookmarks