character string terminated by the null byte (0x00); used in e.g. the C programming language

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 … Wikipedia
🌐
Wikipedia
en.wikipedia.org β€Ί wiki β€Ί Null-terminated_string
Null-terminated string - Wikipedia
March 25, 2025 - This allows the string to contain NUL and made finding the length need only one memory access (O(1) (constant) time), but limited string length to 255 characters. C designer Dennis Ritchie chose to follow the convention of null-termination to avoid the limitation on the length of a string and because maintaining the count seemed, in his experience, less convenient than using a terminator.
🌐
Eskimo
eskimo.com β€Ί ~scs β€Ί cclass β€Ί notes β€Ί sx8.html
Chapter 8: Strings
The end of the string is marked with a special character, the null character, which is simply the character with the value 0. (The null character has no relation except in name to the null pointer. In the ASCII character set, the null character is named NUL.)
🌐
University of Kent
cs.kent.edu β€Ί ~durand β€Ί CS2 β€Ί Notes β€Ί 01_Intro β€Ί c2_stringCstyle.html
C-Style Strings
There are two ways to keep track of the the number of items in an array: ... A C-style string is a null (denoted by \0) terminated char array. The null occurs after the last character of the string. For an initialization using double quotes, "...", the compiler will insert the null.
🌐
Quora
quora.com β€Ί In-C-programming-which-one-of-the-following-is-the-string-termination-character
In C programming, which one of the following is the string termination character? - Quora
When showed those numbers are translated into characters according to a table, normally the ASCI character table, where each number represent a letter. The number zero (0) has been designated to represent the termination character. So...
🌐
TutorialsPoint
tutorialspoint.com β€Ί cprogramming β€Ί c_strings.htm
Strings in C
A string in C is a one-dimensional array of char type, with the last character in the array being a "null character" represented by '\0'. Thus, a string in C can be defined as a null-terminated sequence of char type values.
🌐
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.
Find elsewhere
🌐
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.
🌐
C For Dummies
c-for-dummies.com β€Ί blog
Safe Coding Practices – Terminating a String | C For Dummies Blog
Therefore, a must equal 26 after the for loop is done. At that position β€” alphabet+a or the 27th element of the array β€” the character \0 is set, terminating the string. The code is now safe and the string will be handled properly elsewhere in the code because its null-terminated.
🌐
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....
🌐
Weber State University
icarus.cs.weber.edu β€Ί ~dab β€Ί cs1410 β€Ί textbook β€Ί 8.Strings β€Ί c_string.html
8.2. C-Strings
C-Strings are character arrays ... of the string text with a special character called the null termination character. The null termination character or null terminator is the character equivalent of zero, which C++ denotes with the escape sequence '\0' (where the escaped character is the digit ...
🌐
LabEx
labex.io β€Ί tutorials β€Ί c-how-to-ensure-string-null-termination-438491
How to ensure string null termination | LabEx
In C programming, a null-terminated string is a character array that ends with a special null character '\0'. This null character serves as a marker to indicate the end of the string, allowing functions to determine the string's length and prevent ...
🌐
Tutorial and Example
tutorialandexample.com β€Ί null-character-in-c
Null character in C - TAE
The Null character in the C programming language is used to terminate the character strings. 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 ...
🌐
Quora
quora.com β€Ί Why-are-C-string-null-terminated
Why are C-string null terminated? - Quora
Answer (1 of 10): Bell Labs were a telecommunications company. Their designers thought in terms of telecommunications which were not reliable at transmitting data. This meant that transmissions needed to be framed with start and stop bit (a unique pattern that could not occur in data). The advan...
🌐
SEI CERT
wiki.sei.cmu.edu β€Ί confluence β€Ί x β€Ί r9UxBQ
STR32-C. Do not pass a non-null-terminated character ...
The requested service is temporarily unavailable Β· We would like to apologize for any inconvenience that this may cause