November 2013
Beginner
325 pages
9h 47m
English
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 an address 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
}
Sometimes NULL indicates that there is no value, so you might see something like this:
float *measuredGravityPtr ...
Read now
Unlock full access