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
- What is a Pointer to a Null pointer
- NULL undeclared error in C/C++ and how to resolve it
- Difference between Optical Character Recognition (OCR) and Magnetic Ink Character Reader (MICR)
- Pointer Expressions in C with Examples
- Pointer Arithmetics in C with Examples
- Difference between String and Character array in Java
- Difference between pointer to an array and array of pointers
- Check whether the given character is in upper case, lower case or non alphabetic character
- 'this' pointer in C++
- Difference between an Integer and int in Java with Examples
- Difference between Argument and Parameter in C/C++ with Examples
- Difference between cout and puts() in C++ with Examples
- Difference between Iterators and Pointers in C/C++ with Examples
- void pointer in C / C++
- Difference between Abstraction and Encapsulation in Java with Examples
- Difference between Iterator and Enumeration in Java with Examples
- Difference between Java and Kotlin in Android with Examples
- C | Pointer Basics | Question 15
- C | Pointer Basics | Question 16
- C | Pointer Basics | Question 17
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.