Nearby lessons
55 of 72C - NULL Pointer
Learn what a NULL pointer means and why you should check a pointer before using it.
What Is a NULL Pointer?
A pointer set to NULL does not point to a valid object. It is useful when you do not have an address to store yet.
Example01
Assigning an Address Later
After creating a pointer with NULL, you can assign it the address of a variable. Only use *ptr after it points to a valid variable.
Example02
Important Rule
Never read or write *ptr while ptr == NULL. It can cause the program to behave incorrectly or crash.
📝 Key Takeaways
- NULL means a pointer is not pointing to a valid object.
- A NULL pointer should not be dereferenced.
- Check a pointer before using *ptr.
🧠 Test Your Knowledge
1 QuestionsProgress: 0 / 1