Difference Between NULL Pointer and Void Pointer in C
The following table list the differences between a null pointer and a void pointer in C:
NULL Pointer |
Void Pointer |
---|---|
A NULL pointer does not point to anything. It is a special reserved value for pointers. | A void pointer points to the memory location that may contain typeless data. |
Any pointer type can be assigned NULL. | It can only be of type void. |
All the NULL pointers are equal. | Void pointers can be different. |
NULL Pointer is a value. | A void pointer is a type. |
Example: int *ptr = NULL; | Example: void *ptr; |
NULL Pointer in C
The Null Pointer is the pointer that does not point to any location but NULL. According to C11 standard:
“An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.”