Null Pointer
It is a pointer that does not point to any memory location. It represents an invalid memory location.
When NULL value is assigned to a pointer, then it is considered as NULL Pointer.
Uses of NULL Pointer:
- Used to initialise pointer
- Useful to handling errors in dynamic memory allocation
The value of NULL is 0. We can use either NULL or 0 to initialise pointer but 0 is not integer here.
Size of the NULL pointer depends upon the platform and is similar to the size of normal pointer.
It is a good practice to initialise a pointer as NULL.
It is also a good practice to perform NULL check before dereferencing any pointer to avoid surprises.
#include<stdio.h>
void main()
{
int *ptr=NULL;
printf(“%d”,ptr);
printf(“n%d”,sizeof(NULL));
}