The integer constant zero(0) has different meanings depending upon it’s used. In all cases, it is an integer constant with the value 0, it is just described in different ways.
If any pointer is being compared to 0, then this is a check to see if the pointer is a null pointer. This 0 is then referred to as a null pointer constant. The C standard defines that 0 is typecast to (void *) is both a null pointer and a null pointer constant.
The macro NULL is provided in the header file “stddef.h”.
Below are the ways to check for a NULL pointer:
- NULL is defined to compare equal to a null pointer as:
if(pointer == NULL)
- Below if statement implicitly checks “is not 0”, so we reverse that to mean “is 0” as:
‘\0’ is defined to be a null character. It is a character with all bits set to zero. This has nothing to do with pointers. ‘\0’ is (like all character literals) an integer constant with the value zero.
- Below statement checks if the string pointer is pointing at a null character.
- Below statement checks if the string pointer is pointing at a not-null character.
In C language string is nothing but an array of char type. It stores each of the characters in a memory space of 1 byte. Each array is terminated with ‘\0’ or null character but if we store a ‘0’ inside a string both are not same according to the C language. ‘0’ means 48 according to the ASCII Table whereas ‘\0’ means 0 according to the ASCII table.
Below is the C program to print the value of ‘\0’ and ‘0’:
\0 is 0 0 is 48