NULL Pointer in C: Definition and Usage
☰Fullscreen
Table of Content:
Null Pointer
- NULL Pointer is a pointer which is pointing to nothing.
- The NULL pointer points the base address of the segment.
- In case, if you don’t have an address to be assigned to a pointer then you can simply use NULL
- The pointer which is initialized with the NULL value is considered as a NULL pointer.
- NULL is a macro constant defined in following header files –
stdio.h
alloc.h
mem.h
stddef.h
stdlib.h
Defining NULL Value
#define NULL 0
Below are some of the variable representations of a NULL pointer.
float *ptr = (float *)0; char *ptr = (char *)0; double *ptr = (double *)0; char *ptr = '\0'; int *ptr = NULL;
Example of NULL Pointer
#includeint main() { int *ptr = NULL; printf("The value of ptr is %u",ptr); return 0; }
Output :
The value of ptr is 0