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 ...
🌐
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).
🌐
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 ...
🌐
Tutorial and Example
tutorialandexample.com β€Ί null-character-in-c
Null character in C - TAE
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.
🌐
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.
🌐
Javatpoint
javatpoint.com β€Ί null-character-in-c
Null character in C - javatpoint
Null character in C with Tutorial, C language with programming examples for beginners and professionals covering concepts, c pointers, c structures, c union, c strings etc.
🌐
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
🌐
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.
🌐
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 ...
🌐
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 ...
🌐
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 ...
🌐
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....
🌐
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 ...
🌐
Quora
quora.com β€Ί In-C-language-is-the-null-character-is-0-or-o
In C language, is the null character is \0 or \o? - Quora
Answer (1 of 7): It may be counter-intuitive, but the C char type is a numerical type (more obvious with the signed char and unsigned char variants). The simple quote syntax is a mere shorthand that will be replaced by the numerical value of the character in the current character set (yes, ASCII...
🌐
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. Let us create a string "Hello". It comprises five char values.
🌐
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 β€Ί @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.