Uploaded November 2026 | Updated November 2026, 5 days ago
Learn about Null Pointers in C programming and understand how to initialize pointers using NULL and the new nullptr constant introduced in C23.
In this tutorial, we first discuss what happens when a pointer is declared without initialization. Using a simple Pointer to int example, we explore why working with an uninitialized pointer can lead to undefined behavior and why pointers should be initialized before use.
Next, we introduce the concept of a Null Pointer. A Null Pointer is a pointer that does not point to any object or function. We learn how to initialize a pointer with NULL when the memory address we want to store is not yet available.
We then discuss the NULL macro provided by the C standard library. You will understand how NULL represents a null pointer constant and how its definition can depend on the implementation.
After that, we learn how to check whether a pointer is null before performing pointer dereferencing. Using if-else conditional statements, we demonstrate how a null pointer evaluates to false and how a non-null pointer evaluates to true in a condition.
Next, we see how a pointer initially containing NULL can later be assigned the address of an integer variable. We use pointer dereferencing to access the integer value and store it in another variable.
We also discuss why assigning NULL to a pointer can be useful when the object it previously pointed to no longer exists, such as after dynamically allocated memory has been freed.
Finally, we introduce nullptr, a predefined null pointer constant added in the C23 standard. We compare NULL and nullptr, explain how nullptr can be used to initialize pointers and check conditions, and discuss compiler support for this modern C feature.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial
Learn about Null Pointers in C programming and understand how to initialize pointers using NULL and the new nullptr constant introduced in C23.
In this tutorial, we first discuss what happens when a pointer is declared without initialization. Using a simple Pointer to int example, we explore why working with an uninitialized pointer can lead to undefined behavior and why pointers should be initialized before use.
Next, we introduce the concept of a Null Pointer. A Null Pointer is a pointer that does not point to any object or function. We learn how to initialize a pointer with NULL when the memory address we want to store is not yet available.
We then discuss the NULL macro provided by the C standard library. You will understand how NULL represents a null pointer constant and how its definition can depend on the implementation.
After that, we learn how to check whether a pointer is null before performing pointer dereferencing. Using if-else conditional statements, we demonstrate how a null pointer evaluates to false and how a non-null pointer evaluates to true in a condition.
Next, we see how a pointer initially containing NULL can later be assigned the address of an integer variable. We use pointer dereferencing to access the integer value and store it in another variable.
We also discuss why assigning NULL to a pointer can be useful when the object it previously pointed to no longer exists, such as after dynamically allocated memory has been freed.
Finally, we introduce nullptr, a predefined null pointer constant added in the C23 standard. We compare NULL and nullptr, explain how nullptr can be used to initialize pointers and check conditions, and discuss compiler support for this modern C feature.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial










