🌐
Sanfoundry
sanfoundry.com β€Ί c-tutorials-null-character
NULL Character in C - Sanfoundry
April 18, 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).

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
1 week ago - 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 '\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
Why the NULL character is not right after the last index of this array?
You've got an array with 5 elements, that's indexes 0 to 4. ... Any output you get is fortunate, it could even crash. 1 comment Show comments for this answer Report a concern ... That's not the reality because the null character should stay after the last index element, even if the array is ... More on learn.microsoft.com
🌐 learn.microsoft.com
6
0
October 31, 2023
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
🌐
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 ...
🌐
University of Texas
farside.ph.utexas.edu β€Ί teaching β€Ί 329 β€Ί lectures β€Ί node21.html
Character strings
The null character is automatically added to the end of any character string enclosed in double quotes. Note that, since all character strings in C must be terminated by the (invisible) null character, it takes a character array of size at least n+1 to store an n-letter string.
🌐
ScienceDirect
sciencedirect.com β€Ί topics β€Ί computer-science β€Ί null-character
Null Character - an overview | ScienceDirect Topics
For example, the string β€œHello ... the final byte β€œ00000000” encodes the null character. In the C programming language, the null byte (with value 0) terminates a character string....
🌐
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.
Find elsewhere
🌐
OSDev Wiki
wiki.osdev.org β€Ί Null_Character
Null Character - OSDev Wiki
March 12, 2024 - 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 ...
🌐
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 ...
🌐
Microsoft Learn
learn.microsoft.com β€Ί en-us β€Ί answers β€Ί questions β€Ί 1410960 β€Ί why-the-null-character-is-not-right-after-the-last
Why the NULL character is not right after the last index of this array? - Microsoft Q&A
October 31, 2023 - //not valid in C++, valid in ISO C where a will be 5 chars with no NUL char a[5] = "ancde"; //valid in C++ and valid in ISO C - a will be 6 chars with NUL at end char a[] = "ancde"; ... WayneAKing, Barry Schwarz, Bruce (SqlWork.com), RLWA32, David Lowndes, Minxin Yu. That's not the reality because the null character should stay after the last index element, even if the array is full or empty.
🌐
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.
🌐
Medium
medium.com β€Ί @amey0x β€Ί null-byte-vs-null-terminator-vs-null-character-f25fc0ebc3f6
Null Byte vs Null terminator vs Null character πŸ˜΅β€πŸ’« | by Aman singh | Medium
October 27, 2023 - Null character: The null character is a non-printing character that is used to represent the end of a string. It is also used to represent empty values in some data types. Null terminator: The null terminator is a byte with the value zero that ...
🌐
Startup House
startup-house.com β€Ί homepage β€Ί glossary β€Ί null character
Null Character: The Silent Sentinel of String Termination | Startup House
A null character, typically denoted as '\0', is a character with all its bits set to zero. In the realm of programming, especially in languages like C and C++, this character is widely used to mark the end of a string, a role that has earned ...
🌐
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.
🌐
Sololearn
sololearn.com β€Ί en β€Ί Discuss β€Ί 2111320 β€Ί what-is-0-in-c-language-and-what-is-its-use-with-example-please
What is \0 in C language and what is it's use? (with example please). | Sololearn: Learn to code for FREE!
December 25, 2019 - '\0' is referred to as NULL character or NULL terminator It is the character equivalent of integer 0(zero) as it refers to nothing In C language it is generally used to mark an end of a string.
🌐
DevX
devx.com β€Ί home β€Ί null character
Null Character - Glossary
January 17, 2024 - Also known as the null terminator or NUL, the null character is important for proper string handling in many programming languages such as C, which use it to mark the end of a string when storing it in memory.
🌐
TutorialsPoint
tutorialspoint.com β€Ί what-is-a-null-terminated-string-in-c-cplusplus
What is a null-terminated string in C/C++?
June 13, 2025 - In C, the strings are basically ... terminated strings are basically a sequence of characters, and the last element is one null character (denoted by '\0')....
🌐
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
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 the string).
🌐
W3Schools
w3schools.com β€Ί c β€Ί c_strings.php
C Strings
For example, "Hello World" is a string of characters. Unlike many other programming languages, C does not have a String type to easily create string variables. Instead, you must use the char type and create an array of characters to make a string in C:
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί c language β€Ί strings-in-c
Strings in C - GeeksforGeeks
3 weeks ago - A string is an array of characters terminated by a special character '\0' (null character). This null character marks the end of the string and is essential for proper string manipulation.