Previous | Home | Next |
# NULL Pointer
A pointer that is assigned NULL is called a null pointer. In that case no need to assigned to the exact address. This is done at the time of variable declaration. If a pointer contains the null (zero) value, it is assumed to point to nothing.
The NULL pointer is a constant with a value of zero defined in several standard libraries. Consider the following program:
#include <stdio.h> void main () { int *ptr = NULL; printf("The value of ptr is : %x\n", ptr ); }
The value of ptr is 0
Note: On most of the operating systems, programs are not permitted to access memory at address 0 because that memory is reserved by the operating system.
To check for a null pointer you can use an if statement as follows:
if(ptr) /* succeeds if p is not null */ if(!ptr) /* succeeds if p is null */
Previous | Home | Next |