Sometimes you need a pointer to nothing. That is, you have a variable that can hold an address, and you want to store something in it that makes it explicit that the variable is not set to anything. We use NULL for this:
float *myPointer; // Set myPointer to NULL for now, I'll store a pointer there // later in the program myPointer = NULL;
What is NULL? Remember that an address is just a number. NULL is zero. This is very handy in if statements:
float *myPointer; ... // Has myPointer been set? if (myPointer) { // myPointer is not NULL ...do something with the data at myPointer... } else { // myPointer is NULL }
Later, when we discuss pointers to objects, we will use nil instead of NULL. They are equivalent, but Objective-C programmers use nil to mean the address where no object lives.