The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
Home Pointers and References The Null Pointer | ||
The Null Pointer
int main() { int x = 12345; int* px = &x; while (px) { cout << "Pointer px points to something\n"; px = 0; } cout << "Pointer px points to null, nothing, nada!\n"; return 0; } If pointer px is NOT null, then it is pointing to something, however, if the pointer is null, then it is pointing to nothing. The null pointer becomes very useful when you must test the state of a pointer, whether it has a value or not.
|
||
Home Pointers and References The Null Pointer |