NULL Character in C

In the C programming language, character strings are terminated by using NULL Character. Integer constant zero (0) has many usages depending upon how the programmer uses it. A NULL byte is represented by ‘\0’ or ‘0’ (zero) or NULL. A NULL character is the one that sets all bits to zero. The C programming language does not have an explicit string data type; hence comes to the question of how strings that are an integral component of the program are to be handled. This requires the use of a character that can terminate the character arrays so the same can be treated as strings.

Here, in such cases, a NULL character does not have any graphic printable symbol associated with it and is consequently not required, and this is the reason why it is referred to as a string terminator. NULL stores each of the characters in the memory space of 1 byte. Each array is terminated with ‘\0’ or NULL, but we store a ‘0’ inside a string. ‘0’ in ASCII value equates to a numerical of 48, whereas ‘\0’ means 0 in ASCII table as well.

Many concepts in C, such as character strings and string literals, are terminated by a NULL byte. String literals do not have a visible NULL terminator. The compiler provides every string literal a NULL character every time the program is being compiled. But character arrays may or may not contain NULL terminator; hence the character arrays which contain NULL bytes are strings.


Non string data can consist of any NULL characters. But the string handling functions are particular with the strings and cannot deal with any of the non-string data provided. Hence to process non string data, usage of memory functions will be recommended. The integer constant, that is, zero has many different meanings depending on its usage. In most cases, it will be an integer constant with the value 0 but will be described in other forms. Macro NULL is provided by the header file “stddef.h”. We can check the NULL pointer in the following ways:

If the above statement implicitly checks “is not 0”, we can reverse that to “is 0.”

  • Statement to check if the string pointer is pointing to a NULL character:
  • Statement to check whether the string pointer is pointing at a non-NULL character:

Eg: Program to print the value of ‘\0’ and ‘0’:


Let’s take an example of declaring a null pointer of type int:

This pointer will point to an integer, but at the moment, it points to nothing. NULL pointers can be used when allocating dynamic memory for the data, such as:

Advantages of using NULL Character:

The main advantage of using the NULL terminator is that we can check whether a value is null quickly. In theory, any of the other variables could have been used instead of NULL, but usage of such might require an explicit comparison for a specific value. Every time the result of a calculation is zero, a flag is automatically set in the status register, and this can be used in conditional instructions, such as conditional jump.

Hence the use of NULL has added advantage as it represents invalid value pointers. The language specification, especially in the C standard library, treats a NULL character as a special value for a pointer, there will be no difference for the processor core. The address zero is as good for an address as any other number. Whenever a NULL is not used for signaling an invalid value, it can be used for a valid address.

Pin It on Pinterest

Share This