control character whose bits are all 0
The null character is a control character with the value zero. Many character sets include a code point for a null character – including Unicode (Universal Coded Character Set), ASCII (ISO/IEC 646), … Wikipedia
🌐
Wikipedia
https://en.wikipedia.org β€Ί wiki β€Ί Null_character
Null character - Wikipedia
October 10, 2026 - In software documentation, the null character is often represented with the text NUL (or NULL although that may mean the null pointer). In Unicode, there is a character for this: U+2400 ␀ SYMBOL FOR NULL.
🌐
Reddit
https://reddit.com β€Ί r/learnprogramming β€Ί null character in c
r/learnprogramming on Reddit: NULL character in C
March 7, 2023 -

So, it's represented by '\0' or '0', right?

Why '0' too when it's value is 48 and not 0 - is it not the character '0' in ASCII but the symbol '0' used when talking about the NULL character?

EDIT: So it's just the ASCII character '\0'.

ALSO: Why is a char array printable as a string even if it contains no NULL character?

#include <stdio.h>

int main(void)
{
    char s[] = {'h', 'i', '.', '.'};
    printf("%s\n", s);
    printf("%i %i %i %i\n", s[0], s[1], s[2], s[3]);
}

prints

hi..
104 105 46 46

but if I change the last line to

printf("%i %i %i %i %i\n", s[0], s[1], s[2], s[3], s[4);

it complains "array index 4 is past the end of the array" which means there is no NULL.

EDIT: I just used the code above and changed s[] to s[5] and it printed the additional 0 - why - can't printf see the NULL if you declare the array without specifying its size in advance?

Discussions

c - How does one represent the empty char? - Stack Overflow
I'm currently writing a little program but I keep getting this error when compiling error: empty character constant I realize it's because I'm trying to replace a valid char with empty space c[i]... More on stackoverflow.com
🌐 stackoverflow.com
c - What is the difference between NULL, '\0' and 0? - Stack Overflow
In C, there appear to be differences between various values of zero -- NULL, NUL and 0. I know that the ASCII character '0' evaluates to 48 or 0x30. The NULL pointer is usually defined as: #define More on stackoverflow.com
🌐 stackoverflow.com
C - why can't we store the null character at the beginning of a string?
Sure you can. What makes you think you can't? By definition, C strings are terminated by a null character, so saying the null character is at the beginning of a string is just another way of saying the string is empty. More on reddit.com
🌐 r/learnprogramming
12
2
February 28, 2023
NULL character in C
All ASCII characters have an associated number with it. A single space has the ASCII value of 10. The ASCII character '0' has an ASCII value of 48. The null character (which is NOT '0') has an ASCII value of 0. In particular char ch = 0; // ASCII value 0 char ch2 = '\0'; // ASCII value 0 char ch3 = '0'; // ASCII value 48 So, '0' and 0 are not the same thing. More on reddit.com
🌐 r/learnprogramming
5
0
March 7, 2023
People also ask

How does the null character relate to the concept of 'null' in other programming contexts?
While the null character ('0') is specific to strings and termination in languages like C, the concept of 'null' in other programming contexts generally refers to the absence of a value or a non-existent reference. It's crucial to differentiate between the null character used for string termination and the broader concept of 'null' or 'null values'in languages like Java, JavaScript, or structured query language (SQL).
🌐
lenovo.com
lenovo.com β€Ί home
What is a Null Character? A Comprehensive Explanation | Lenovo US
What is a null character?
In programming, a null character, often denoted as '0', is a special character with all its bits set to zero. It doesn't represent a visible character like 'A' or '1', but rather serves to terminate strings in languages like C. Essentially, it shows the end of a sequence of characters. This little zero-packed warrior is more of a behind-the-scenes hero, ensuring that your programs know where the strings end.
🌐
lenovo.com
lenovo.com β€Ί home
What is a Null Character? A Comprehensive Explanation | Lenovo US
What's the significance of the null character in programming languages like C?
In languages like C, the null character is the unsung hero of string handling. Its primary role is to serve as the terminator for strings. Without it, functions that manipulate strings wouldn't know where a string ends. Imagine a book without spaces, punctuation, or paragraph breaks – the null character ensures that your program doesn't get lost in a jumble of characters.
🌐
lenovo.com
lenovo.com β€Ί home
What is a Null Character? A Comprehensive Explanation | Lenovo US
🌐
Sanfoundry
https://sanfoundry.com β€Ί c-tutorials-null-character
NULL Character in C with Examples
December 31, 2025 - Understand the null character ('\0') in C with clear examples. Learn its role in strings, key differences, and avoid common mistakes.
🌐
Tutorial and Example
https://tutorialandexample.com β€Ί null-character-in-c
Null character in C - TAE
March 28, 2022 - In other words, the Null character is used to represent the end of the string or end of an array or other concepts in C. The end of the character string or the NULL byte is represented by β€˜0’ or β€˜\0’ or simply NULL. The NULL character doesn’t have any designated symbol associated ...
🌐
GeeksforGeeks
https://geeksforgeeks.org β€Ί c language β€Ί difference-between-null-pointer-null-character-0-and-0-in-c-with-examples
Difference between NULL pointer, Null character ('\0') and '0' in C with Examples - GeeksforGeeks
July 15, 2025 - 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".
🌐
Lenovo
https://lenovo.com β€Ί home
What is a Null Character? A Comprehensive Explanation | Lenovo US
In programming, a null character, often denoted as '\0', is a special character with all its bits set to zero. It doesn't represent a visible character like 'A' or '1', but rather serves to terminate strings in languages like C. Essentially, it shows the end of a sequence of characters.
Find elsewhere
🌐
Javatpoint
https://javatpoint.com β€Ί null-character-in-c
Null character in C - javatpoint
These points are called articulation points. They represent the vulnerabilities in each network provided to the machine for either traversal or prediction. To... ... Operators are the predefined symbols of the C/C++ library, and it is used to perform logical as well as mathematical operations to the operands.
🌐
ASCII Code
https://ascii-code.com β€Ί character β€Ί ␀
Null character - ASCII Code
Detailed information about ASCII character ␀, also known as the null character
🌐
Linux Hint
https://linuxhint.com β€Ί null-character-c
How to Use NULL Character in C with Examples – Linux Hint
In C programming, a NULL character ends the character strings. The symbol for it is β€˜\0β€˜ or NULL. Although the NULL character serves many different kinds of operations, its main objective is to end a string, array, or other C concept. This tutorial taught us what is the NULL character and how to use it in C programming.
🌐
W3Schools
https://w3schools.com β€Ί c β€Ί c_null.php
C NULL
NULL is a special value that represents a "null pointer" - a pointer that does not point to anything.
🌐
W3Schools
https://w3schools.com β€Ί c β€Ί c_strings_null.php
C Strings - The Null Character
Every string in C ends with a special character, \0, known as the null character. It tells C where the string ends.
🌐
cppreference.com
https://en.cppreference.com β€Ί c β€Ί types β€Ί NULL
NULL - cppreference.com
POSIX requires NULL to be defined as an integer constant expression with the value 0 cast to void*.
Top answer
1 of 11
446

Note: This answer applies to the C language, not C++.


Null Pointers

The integer constant literal 0 has different meanings depending upon the context in which it's used. In all cases, it is still an integer constant with the value 0, it is just described in different ways.

If a pointer is being compared to the constant literal 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 cast to the type void * is both a null pointer and a null pointer constant.

Additionally, to help readability, the macro NULL is provided in the header file stddef.h. Depending upon your compiler it might be possible to #undef NULL and redefine it to something wacky.

Therefore, here are some valid ways to check for a null pointer:

if (pointer == NULL)

NULL is defined to compare equal to a null pointer. It is implementation defined what the actual definition of NULL is, as long as it is a valid null pointer constant.

if (pointer == 0)

0 is another representation of the null pointer constant.

if (!pointer)

This if statement implicitly checks "is not 0", so we reverse that to mean "is 0".

The following are INVALID ways to check for a null pointer:

int mynull = 0;
<some code>
if (pointer == mynull)

To the compiler this is not a check for a null pointer, but an equality check on two variables. This might work if mynull never changes in the code and the compiler optimizations constant fold the 0 into the if statement, but this is not guaranteed and the compiler has to produce at least one diagnostic message (warning or error) according to the C Standard.

Note that the value of a null pointer in the C language does not matter on the underlying architecture. If the underlying architecture has a null pointer value defined as address 0xDEADBEEF, then it is up to the compiler to sort this mess out.

As such, even on this funny architecture, the following ways are still valid ways to check for a null pointer:

if (!pointer)
if (pointer == NULL)
if (pointer == 0)

The following are INVALID ways to check for a null pointer:

#define MYNULL (void *) 0xDEADBEEF
if (pointer == MYNULL)
if (pointer == 0xDEADBEEF)

as these are seen by a compiler as normal comparisons.

Null Characters

'\0' is defined to be a null character - that is a character with all bits set to zero. '\0' is (like all character literals) an integer constant, in this case with the value zero. So '\0' is completely equivalent to an unadorned 0 integer constant - the only difference is in the intent that it conveys to a human reader ("I'm using this as a null character.").

'\0' has nothing to do with pointers. However, you may see something similar to this code:

if (!*char_pointer)

checks if the char pointer is pointing at a null character.

if (*char_pointer)

checks if the char pointer is pointing at a non-null character.

Don't get these confused with null pointers. Just because the bit representation is the same, and this allows for some convenient cross over cases, they are not really the same thing.

References

See Question 5.3 of the comp.lang.c FAQ for more. See this pdf for the C standard. Check out sections 6.3.2.3 Pointers, paragraph 3.

2 of 11
45

It appears that a number of people misunderstand what the differences between NULL, '\0' and 0 are. So, to explain, and in attempt to avoid repeating things said earlier:

A constant expression of type int with the value 0, or an expression of this type, cast to type void * is a null pointer constant, which if converted to a pointer becomes a null pointer. It is guaranteed by the standard to compare unequal to any pointer to any object or function.

NULL is a macro, defined in as a null pointer constant.

\0 is a construction used to represent the null character, used to terminate a string.

A null character is a byte which has all its bits set to 0.

🌐
Computer Hope
https://computerhope.com β€Ί jargon β€Ί n β€Ί nullchar.htm
What Is a Null Character?
January 6, 2025 - Null has an ASCII (American Standard Code for Information Interchange) decimal value of 0.
🌐
Medium
https://medium.com β€Ί @maxnegi333 β€Ί what-is-a-null-character-in-c-programming-7d91a78f18ca
What is a Null character in C programming? - Mayanknegi - Medium
September 20, 2023 - In the C programming language, character strings are terminated with the Null character. To put it another way, the Null character in C stands for the end of a line, an array, or other concepts.
🌐
PrepBytes
https://prepbytes.com β€Ί home β€Ί c programming β€Ί null character in c
Null Character in C
August 3, 2023 - The Null Character in C is a special character with an ASCII value of 0 (zero).
🌐
Flavio Copes
https://flaviocopes.com β€Ί home β€Ί null in c: what it is, how to check for it, and c23 nullptr
NULL in C: what it is, how to check for it, and C23 nullptr
February 13, 2020 - See how to check a pointer against it, avoid the segfault, and when to use C23's nullptr. In C, NULL is a macro that represents a null pointer: a pointer that points to nothing.
🌐
Asciihex
https://asciihex.com β€Ί character β€Ί control β€Ί 0 β€Ί 0x00 β€Ί nul-null-character
ASCII Table: ASCII character NUL - Null character. ^@. Dec: 0, Bin: 00000000, Hex: 00
Let's move in to some descriptive facts of this character. So, the null character (also null terminator or null byte), or briefly NUL, is a control character with the value zero. Lots of character sets have it, including ISO/IEC 646 (or ASCII), ...
🌐
University of Texas
https://farside.ph.utexas.edu β€Ί teaching β€Ί 329 β€Ί lectures β€Ί node21.html
Character strings
The resulting elements of word are as follows: word[0] = 'f' word[1] = 'o' word[2] = 'u' word[3] = 'r' word[4] = '\0' with the remaining elements undefined. Here, 'f' represents the character ``f'', etc., and '\0' represents the so-called null character (ASCII code 0), which is used in C to ...