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.

E.g.:

char vowel[] = {‘a’, ‘e’, ‘i’, ‘o’, ‘u’}; //character array

char vowel[] = {‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘\0’}; //character string

char *str = “Hello World”; //string literal with no visible NULL character

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 (pointer == NULL) or if (!pointer)

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:

if (!* string pointer)

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

if (* string pointer)