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
en.wikipedia.org โ€บ wiki โ€บ Null_character
Null character - Wikipedia
March 3, 2026 - A null-terminated string is a commonly used data structure in the C programming language, its many derivative languages and other programming contexts that uses a null character to indicate the end of a string. This design allows a string to be any length at the cost of only one extra character ...
Discussions

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
string - About Null character in C language - Stack Overflow
It gives the following output (with ... a smiley symbol: ... Thanks in advance. ... The array c is only 5 characters wide, and the initializer given has too many characters for an array that size. So only the first 5 characters of the string constant are used to initialize the array. This means that the array contains only the characters 'h', 'e', 'l', 'l', and 'o'. In other words, you don't have a string because it's not null ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
c - How does one represent the empty char? - Stack Overflow
If you understands strings then ... c = ''; is not valid as below explained in 6 answers. ... You can use c[i]= '\0' or simply c[i] = (char) 0. The null/empty char is simply a value of zero, but can also be represented as a character with an escaped zero.... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Null character '\0' & null terminated strings
should the strings be terminated by NUL in that character set, or by a character whose value is zero? The character '\0' is guaranteed to be a byte with all bits zero, and to have a numeric value equal to zero. A string in C always ends with this character. Then, according to Wikipedia, the null character is encoded as two bytes 0xC0, 0x80. No, in standard UTF-8 the code point with value zero is encoded in a single zero byte. You may have been reading something about "modified UTF-8", which appears to be a rather Java-centric external encoding for strings. It deliberately uses an "overlong" encoding of Java '\u0000' so that the resulting byte sequence does not contain a zero byte. One reason for this is because the length of strings in Java is not defined by use of a terminating character โ€” a Java string can contain arbitrary '\u0000' characters โ€” and you might need some way to round-trip such strings between Java and a language like C that does use a zero byte as a terminator. More on reddit.com
๐ŸŒ r/C_Programming
14
17
December 25, 2022
๐ŸŒ
GeeksforGeeks
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 - 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 Characters('\0'): '\0' is defined to be a null character.
๐ŸŒ
Sanfoundry
sanfoundry.com โ€บ c-tutorials-null-character
NULL Character in C with Examples
December 31, 2025 - These terms may look similar, but they serve different purposes in C: โ€˜0โ€™: A character that represents the digit zero. It has an ASCII value of 48. ... NULL: A macro that represents a null pointer, usually defined as ((void*)0).
๐ŸŒ
Reddit
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?

๐ŸŒ
OSDev Wiki
wiki.osdev.org โ€บ Null_Character
Null Character - OSDev Wiki
The null character, also known as the null terminator, is a character with the value of zero. Besides representing a NOP, nowadays it is known as the control character that indicates the end of an string in C-like data formats. In essence, the null terminator is a way to encode the end of a ...
๐ŸŒ
Linux Hint
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.
Find elsewhere
๐ŸŒ
Tutorial and Example
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 with it and also it is not required consequently.
๐ŸŒ
Codedamn
codedamn.com โ€บ news โ€บ c programming
What is \ 0 (null byte) in C? Explained with examples.
November 9, 2023 - Amid its many intricate constructs, the \0 character holds a unique place. Let's delve into its significance and how it's become a fundamental building block, especially when dealing with strings.
๐ŸŒ
PrepBytes
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). It is not the same as the character โ€˜0โ€™ which has an ASCII value of 48. The Null Character in C is used to denote the end of a C string, indicating that there ...
๐ŸŒ
Quora
quora.com โ€บ What-is-a-null-character-NUL-on-a-system-level-and-how-can-we-use-it
What is a null character (NUL) on a system level, and how can we use it? - Quora
Answer: NUL is the ASCII character with a numeric value of zero. In C/C++ and close kin the nul character is used to mark the end of a string (rather than using the first byte or word of the โ€œstringโ€ to encode the number of characters in ...
๐ŸŒ
Medium
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 - The character stringโ€™s or byteโ€™s conclusion is represented by the characters โ€œ0,โ€ โ€œ0,โ€ or simply โ€œNULL.โ€ The NULL character does not require it because it does not have a specified mark associated with it.
๐ŸŒ
ScienceDirect
sciencedirect.com โ€บ topics โ€บ computer-science โ€บ null-character
Null Character - an overview | ScienceDirect Topics
For example, the string โ€œHello ... where the final byte โ€œ00000000โ€ encodes the null character. In the C programming language, the null byte (with value 0) terminates a character string....
๐ŸŒ
University of Texas
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 ...
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ null character '\0' & null terminated strings
r/C_Programming on Reddit: Null character '\0' & null terminated strings
December 25, 2022 -

Hello everyone!
In C, strings (character arrays) are terminated by null character '\0' - character with value zero.
In ASCII, the NUL control code has value 0 (0x00). Now, if we were working in different character set (say the machine's character set wouldn't be ASCII but different one), should the strings be terminated by NUL in that character set, or by a character whose value is zero?

For example, if the machine's character set would be UTF-16, the in C, byte would be 16bits and strings would be terminated by \0 character with value 0x00 00, which is also NUL in UTF-16.
But, what if the machine's character set would be modified UTF-8 (or UTF-7, ...). Then, according to Wikipedia, the null character is encoded as two bytes 0xC0, 0x80. How would be strings terminated in that case? By the byte with value 0 or by the null character.

I guess my question could be rephrased as: Are null terminated strings terminated by the NUL character (which in that character set might be represented by a nonzero value) or by a character whose value is zero (which in that character set might not represent the NUL character).

Thank you all very much and I'm sorry for all mistakes and errors as english is not my first language.

Thanks again.

Top answer
1 of 3
31
should the strings be terminated by NUL in that character set, or by a character whose value is zero? The character '\0' is guaranteed to be a byte with all bits zero, and to have a numeric value equal to zero. A string in C always ends with this character. Then, according to Wikipedia, the null character is encoded as two bytes 0xC0, 0x80. No, in standard UTF-8 the code point with value zero is encoded in a single zero byte. You may have been reading something about "modified UTF-8", which appears to be a rather Java-centric external encoding for strings. It deliberately uses an "overlong" encoding of Java '\u0000' so that the resulting byte sequence does not contain a zero byte. One reason for this is because the length of strings in Java is not defined by use of a terminating character โ€” a Java string can contain arbitrary '\u0000' characters โ€” and you might need some way to round-trip such strings between Java and a language like C that does use a zero byte as a terminator.
2 of 3
17
C11 states: 5.2 Environmental considerations 5.2.1 Character sets 2. In a character constant or string literal, members of the execution character set shall be represented by corresponding members of the source character set or by escape sequences consisting of the backslash \ followed by one or more characters. A byte with all bits set to 0, called the null character, shall exist in the basic execution character set; it is used to terminate a character string. Emphasis is mine From that we can understand that the terminating null character is always completely 0. Then, there's: 5.2.1.2 Multibyte characters A byte with all bits zero shall be interpreted as a null character independent of shift state. Such a byte shall not occur as part of any other multibyte character. 7.1.1 Definitions of terms A string is a contiguous sequence of characters terminated by and including the first null character. The term multibyte string is sometimes used instead to emphasize special processing given to multibyte characters contained in the string or to avoid confusion with a wide string. A pointer to a string is a pointer to its initial (lowest addressed) character. The length of a string is the number of bytes preceding the null character and the value of a string is the sequence of the values of the contained characters, in order.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Null-terminated_string
Null-terminated string - Wikipedia
March 25, 2025 - In computer programming, a null-terminated string is a character string stored as an array containing the characters and terminated with a null character (a character with an internal value of zero, called "NUL" in this article, not same as the glyph zero). Alternative names are C string, which ...
Top answer
1 of 6
88

It doesn't.

The string terminator is a byte containing all 0 bits.

The unsigned int is two or four bytes (depending on your environment) each containing all 0 bits.

The two items are stored at different addresses. Your compiled code performs operations suitable for strings on the former location, and operations suitable for unsigned binary numbers on the latter. (Unless you have either a bug in your code, or some dangerously clever code!)

But all of these bytes look the same to the CPU. Data in memory (in most currently-common instruction set architectures) doesn't have any type associated with it. That's an abstraction that exists only in the source code and means something only to the compiler.

Edit-added: As an example: It is perfectly possible, even common, to perform arithmetic on the bytes that make up a string. If you have a string of 8-bit ASCII characters, you can convert the letters in the string between upper and lower case by adding or subtracting 32 (decimal). Or if you are translating to another character code you can use their values as indices into an array whose elements provide the equivalent bit coding in the other code.

To the CPU the chars are really extra-short integers. (eight bits each instead of 16, 32, or 64.) To us humans their values happen to be associated with readable characters, but the CPU has no idea of that. It also doesn't know anything about the "C" convention of "null byte ends a string", either (and as many have noted in other answers and comments, there are programming environments in which that convention isn't used at all).

To be sure, there are some instructions in x86/x64 that tend to be used a lot with strings - the REP prefix, for example - but you can just as well use them on an array of integers, if they achieve the desired result.

2 of 6
5

In short there is no difference (except that an int is 2 or 4 bytes wide and a char just 1).

The thing is that all modern libaries either use the null terminator technique or store the length of a string. And in both cases the program/computer knows it reached the end of a string when it either read a null character or it has read as many characters as the size tells it to.

Issues with this start when the null terminator is missing or the length is wrong as then the program starts reading from memory it isn't supposed to.