🌐
Sanfoundry
sanfoundry.com β€Ί c-tutorials-null-character
NULL Character in C with Examples
December 31, 2025 - This program creates a string called β€œBootcamp”. It uses strlen() to find the length of the string, which stops at the null character β€˜\0β€˜. The length is stored in the size_t variable len, and then the program prints the length using printf().
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 of memory. The common competing design for a string stores the length of the string as an integer data type, but this limits the size of the string to the range of the integer (for example, 255 for a byte).
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
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
c - How does one represent the empty char? - Stack Overflow
The empty space char would be ' '. If you're looking for null that would be '\0'. ... Yes, c[i]='' is not a valid code. We parenthesis character constant between ' ', e.g. c[i] = 'A'; char A. but you don't write any char in between ''. Empty space is nothing but suppose if you wants to assigned space then do: ... Example... More on stackoverflow.com
🌐 stackoverflow.com
strncpy not working
WTF is feeds_temp? channel_feeds_temp? What are j and k at this point? What are we supposed to be, clairvoyant? Reduce this to some actual code that we can look at. The fact something appears to work at some point doesn't mean you've not caused undefined behavior already. The fact operations don't crash doesn't mean it's "working" either. HOWEVER, let me take this as a wild ass guess that you are trying to swap fields_temp[j][k] with fields_temp[j+1][k].... Well, in that case, you're doing it wrong. Your temp variable in the swap isn't a copy of the string, it's just a pointer to it. You need something like: char temp_sting[WHATEVER_THE_MAX_SIZE_OF_THESE_STRINGS_ARE]; strcpy(temp_string, fields_temp[j][k]); and then strcpy it back later. By the way all this strncpy is pretty pointless. If you know that you didn't overrun the string when you put things in there (and that it was null terminated), then you don't have to keep checking it later (presuming these are all the same size). More on reddit.com
🌐 r/C_Programming
17
0
May 18, 2024
🌐
ScienceDirect
sciencedirect.com β€Ί topics β€Ί computer-science β€Ί null-character
Null Character - an overview | ScienceDirect Topics
In the C programming language, ... allowing functions to determine where the string terminates. 2 For example, the string β€œHello!” is stored in memory as the sequence 0x48 65 6C 6C 6F 21 00, with the null character at the end....
🌐
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.
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com β€Ί cprogramming β€Ί c_strings.htm
Strings in C
In C, the literal representation of a char type uses single quote symbols such as 'H'. These five alphabets put inside single quotes, followed by a null character represented by '\0' are assigned to an array of char types.
🌐
OSDev Wiki
wiki.osdev.org β€Ί Null_Character
Null Character - OSDev Wiki
Example under 64 bit Intel assembly, with NASM: bits 64 global main extern printf section .data str: db "Hello, OSDev!" ; NON-NULL-TERMINATED STRING strnll: db ", and goodbye!", 0 ; NULL-TERMINATED STRING section .text main: lea rdi, [str] xor rax, rax call printf Β· As printf will start reading the characters ...
Find elsewhere
🌐
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 - NULL is defined to compare equal to a null pointer as: ... if(!pointer) Null Characters('\0'): '\0' is defined to be a null character. It is a character with all bits set to zero. This has nothing to do with pointers.
🌐
PrepBytes
prepbytes.com β€Ί home β€Ί c programming β€Ί null character in c
Null Character in C
August 3, 2023 - The Null Character in C is represented using the escape sequence β€˜\0’. It is essential to distinguish it from the character β€˜0’ to prevent potential bugs in string handling. For example, when initializing a character array or a string, it is common to terminate the sequence with a Null ...
🌐
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.
🌐
University of Texas
farside.ph.utexas.edu β€Ί teaching β€Ί 329 β€Ί lectures β€Ί node21.html
Character strings
Here, 'f' represents the character ``f'', etc., and '\0' represents the so-called null character (ASCII code 0), which is used in C to signal the termination of a character string. The null character is automatically added to the end of any character string enclosed in double quotes.
🌐
LabEx
labex.io β€Ί questions β€Ί what-is-the-purpose-of-null-in-a-c-string-array-136081
What is the purpose of NULL in a C string array? | LabEx
July 25, 2024 - By convention, the null terminator is automatically added to the end of the string when it is created or assigned. ... In this example, the myString array contains 14 elements, with the last element being the null terminator \0.
🌐
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.
🌐
University of Kent
cs.kent.edu β€Ί ~durand β€Ί CS2 β€Ί Notes β€Ί 01_Intro β€Ί c2_stringCstyle.html
C-Style Strings
The resulting string includes a null-character at end. Parameters. ... Pointer to a null-terminated string with enough space allocated to contain both src and dest. ... Null-terminated string to append. Return Value. dest is returned. Portability. Defined in ANSI-C. ... /* strcat example */ #include <stdio.h> #include <string.h> int main () { char str[80]; strcpy (str,"strings "); strcat (str,"have been "); strcat (str,"concatenated."); puts (str); return 0; } Output: strings have been concatenated.
🌐
Northern Illinois University
faculty.cs.niu.edu β€Ί ~winans β€Ί CS501 β€Ί Notes β€Ί cstrings.html
C Strings
A "null string" or "empty string" is a string with a null character as its first character: The length of a null string is 0. ... This declaration creates an unnamed character array just large enough to hold the string "Karen" (including room for the null character) and places the address of the first element of the array in the char pointer name:
🌐
Quora
quora.com β€Ί In-the-C-programming-language-why-do-we-need-null-in-char-arrays-but-not-in-arrays-of-other-data-types
In the C programming language, why do we need null in char arrays but not in arrays of other data types? - Quora
I have created lots of char arrays ... for example to just hold an array of predefined data, or to use as a buffer of or a screen data consisting of palette indicies. In these cases, the length of the arrays are predefined, typically using a #define, or the length is derived from the length of the array of predefined data using sizeof(). But when char arrays in C are used as strings, by convention the strings are zero-terminated, which can be represented by NULL, a β€˜\0’ character, or just ...
🌐
Computer Hope
computerhope.com β€Ί jargon β€Ί n β€Ί nullchar.htm
What Is a Null Character?
January 6, 2025 - Below are examples of null characters used in the C and JavaScript programming languages.