Null Pointer in C with easy example

Null pointer in C

In this program, you will learn the concept of null pointer and get the example code of null pointer in c programming.

What is Null Pointer in C

A null pointer is a special type of pointer in C and C++ that points to nothing, not even itself. It represents the absence of any valid pointer.

Null pointer in C

Example

The following is an example of declaring and using a null pointers in C:

// Declaration of null pointer

int *ptr = NULL;

// Check if pointer is null

if (ptr == NULL)

{

printf(“Pointer is null\n”);

}

Size of Null Pointer in C

Size of a null pointer is depends on the architecture and compiler of the system.

On 32 bit system, A null pointer usually has 4 bytes in size.

On 64 bit system, A null pointer usually has 8 bytes in size.

To check the size of a null pointer in c programming, use the ‘sizeof’ operator. Run the following program code to check the size of a null pointer in c programming.

Above program will print the size of a null pointer based on the compiler and system you are using.

Null Pointer in C example

Output

The value of ptr is : 0

 

 

Check out our other C programming Examples

 

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top