Null Pointers
When a memory
allocation function is called, there's always a possibility that it won't be
able to locate a block of memory large enough to satisfy our request. If that
should happen, the function will return a null pointer. A null pointer
is a "pointer to nothing" a special value that can be distinguished
from all valid pointers. After we've stored the function's return value in a
pointer variable, we must test to see if it's a null pointer.
It's the programmer's responsibility to test the return value of any
memory allocation function and take appropriate action if it's a null pointer.
The effect of attempting to access memory through a null pointer is undefined:
the program may crash or behave unpredictably.
No comments:
Post a Comment