Nearby lessons

55 of 72

C - 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
Loading editor…

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
Loading editor…

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 Questions
Progress: 0 / 1

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.