C does not and never has had a native string type. By convention, the language uses arrays of char terminated with a null char, i.e., with '\0'. Functions and macros in the language's standard libraries provide support for the null-terminated character arrays, e.g., strlen iterates over an array of char until it encounters a '\0' character and strcpy copies from the source string until it encounters a '\0'.

The use of null-terminated strings in C reflects the fact that C was intended to be only a little more high-level than assembly language. Zero-terminated strings were already directly supported at that time in assembly language for the PDP-10 and PDP-11.

It is worth noting that this property of C strings leads to quite a few nasty buffer overrun bugs, including serious security flaws. For example, if you forget to null-terminate a character string passed as the source argument to strcpy, the function will keep copying sequential bytes from whatever happens to be in memory past the end of the source string until it happens to encounter a 0, potentially overwriting whatever valuable information follows the destination string's location in memory.

In your code example, the string literal "Hello, world!" will be compiled into a 14-byte long array of char. The first 13 bytes will hold the letters, comma, space, and exclamation mark and the final byte will hold the null-terminator character '\0', automatically added for you by the compiler. If you were to access the array's last element, you would find it equal to 0. E.g.:

const char foo[] = "Hello, world!";
assert(foo[12] == '!');
assert(foo[13] == '\0');

However, in your example, message is only 10 bytes long. strcpy is going to write all 14 bytes, including the null-terminator, into memory starting at the address of message. The first 10 bytes will be written into the memory allocated on the stack for message and the remaining four bytes will simply be written on to the end of the stack. The consequence of writing those four extra bytes onto the stack is hard to predict in this case (in this simple example, it might not hurt a thing), but in real-world code it usually leads to corrupted data or memory access violation errors.

Answer from dgvid on Stack Overflow
🌐
Programiz
programiz.com › c-programming › c-strings
Strings in C (With Examples)
When the compiler encounters a sequence of characters enclosed in the double quotation marks, it appends a null character \0 at the end by default. ... Here, we have declared a string of 5 characters.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - This process is handled efficiently by the strlen() function from the C standard library. ... In this example, strlen() returns the length of the string "Geeks", which is 5, excluding the null character.
🌐
W3Schools
w3schools.com › c › c_strings.php
C Strings
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... Strings are used for storing text/characters. 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.
Top answer
1 of 7
97

C does not and never has had a native string type. By convention, the language uses arrays of char terminated with a null char, i.e., with '\0'. Functions and macros in the language's standard libraries provide support for the null-terminated character arrays, e.g., strlen iterates over an array of char until it encounters a '\0' character and strcpy copies from the source string until it encounters a '\0'.

The use of null-terminated strings in C reflects the fact that C was intended to be only a little more high-level than assembly language. Zero-terminated strings were already directly supported at that time in assembly language for the PDP-10 and PDP-11.

It is worth noting that this property of C strings leads to quite a few nasty buffer overrun bugs, including serious security flaws. For example, if you forget to null-terminate a character string passed as the source argument to strcpy, the function will keep copying sequential bytes from whatever happens to be in memory past the end of the source string until it happens to encounter a 0, potentially overwriting whatever valuable information follows the destination string's location in memory.

In your code example, the string literal "Hello, world!" will be compiled into a 14-byte long array of char. The first 13 bytes will hold the letters, comma, space, and exclamation mark and the final byte will hold the null-terminator character '\0', automatically added for you by the compiler. If you were to access the array's last element, you would find it equal to 0. E.g.:

const char foo[] = "Hello, world!";
assert(foo[12] == '!');
assert(foo[13] == '\0');

However, in your example, message is only 10 bytes long. strcpy is going to write all 14 bytes, including the null-terminator, into memory starting at the address of message. The first 10 bytes will be written into the memory allocated on the stack for message and the remaining four bytes will simply be written on to the end of the stack. The consequence of writing those four extra bytes onto the stack is hard to predict in this case (in this simple example, it might not hurt a thing), but in real-world code it usually leads to corrupted data or memory access violation errors.

2 of 7
18

To note it in the languages you mentioned:

Java:

String str = new String("Hello");

Python:

str = "Hello"

Both Java and Python have the concept of a "string", C does not have the concept of a "string". C has character arrays which can come in "read only" or manipulatable.

C:

char * str = "Hello";  // the string "Hello\0" is pointed to by the character pointer
                       // str. This "string" can not be modified (read only)

or

char str[] = "Hello";  // the characters: 'H''e''l''l''o''\0' have been copied to the 
                       // array str. You can change them via: str[x] = 't'

A character array is a sequence of contiguous characters with a unique sentinel character at the end (normally a NULL terminator '\0'). Note that the sentinel character is auto-magically appended for you in the cases above.

🌐
Systems Encyclopedia
systems-encyclopedia.cs.illinois.edu › articles › c-strings
Strings in C - Systems Encyclopedia
Unlike many higher-level programming languages, C does not feature an explicit string type. While C does allow string literals, strings in C are strictly represented as character arrays terminated with a null byte (\0 or NUL).
🌐
Wikipedia
en.wikipedia.org › wiki › C_string_handling
C string handling - Wikipedia
December 9, 2025 - The C programming language has a set of functions implementing operations on strings (character strings and byte strings) in its standard library. Various operations, such as copying, concatenation, tokenization and searching are supported. For character strings, the standard library uses the ...
🌐
Wikibooks
en.wikibooks.org › wiki › C_Programming › String_manipulation
C Programming/String manipulation - Wikibooks, open books for an open world
November 9, 2025 - The editor should also be able to handle the encoding if strings shall be able to be written in the source code. ... One byte per character. Normally based on ASCII. There is a limit of 255 different characters plus the zero termination character. Variable length char strings, which allows ...
Find elsewhere
🌐
Reddit
reddit.com › r/c_programming › new to c. if c does not have strings, then what exactly is printf doing?
r/C_Programming on Reddit: New to C. If C does not have strings, then what exactly is printf doing?
January 26, 2022 -

Brand new to C, and I am told that there is no string data type. So I am just curious, if that id the case, then how exactly is something like: printf(“Hello World”) a thing?

Top answer
1 of 8
123
C does have strings. It doesn't have a "string data type", but it has strings. A string object in C is not a string because the type system says it's a string, it's a string because of the nature of the bytes that make up the object. Specifically, a C string is "a contiguous sequence of characters terminated by and including the first null character". That definition makes no reference to types at all. This might sound a bit pedantic, but it's actually pretty important. Let's say you have an object declared as follows: char str[100]; Does this object identify a string or not? We cannot answer this unless we know the value being stored in the object. The value might be a string, or it might not be. The type system does not tell us. Somebody just asked me "what is a character in C"... but then they deleted the question. I suspect it was going to lead on to "isn't char a data type?" Yes, char is a data type. But in C a character is given the somewhat more abstract definition "member of a set of elements used for the organization, control, or representation of data", as well as the practical definition of a value stored in a single byte. Essentially I see the notion of a character as being a description of a value, not the type of that value. Characters are often stored in char objects, but they can also be stored in other type objects, like unsigned char and int. For the "character as an element of a string" sense, however, one must think of these characters as being in contiguous bytes in memory. One might typically use a char pointer or an array of char to denote such an object, since they allow you to directly address each character in the string individually. A void pointer would not let you do this so easily, for instance, even though it could just as well point to the first character of a string.
2 of 8
41
In C, there is not default string type. A C string is an array of characters terminated (last character) by null. Printf changes depending on the platform but for something like your pc it’s just formatting an array of characters terminated by a null and inserting it inside the stdout file stream.
🌐
Yale University
cs.yale.edu › homes › aspnes › pinewiki › C(2f)Strings.html
C/Strings
If you want to use counted strings instead, you can build your own using a struct (see C/Structs). Most scripting languages written in C (e.g. Perl, Python_programming_language, PHP, etc.) use this approach internally. (Tcl is an exception, which is one of many good reasons not to use Tcl).
🌐
HowStuffWorks
computer.howstuffworks.com › tech › computer software › programming
Strings - The Basics of C Programming | HowStuffWorks
March 8, 2023 - But why is a 100-element array unable to hold up to 100 characters? Because C uses null-terminated strings, which means that the end of any string is marked by the ASCII value 0 (the null character), which is also represented in C as '\0'. Null ...
🌐
TutorialsPoint
tutorialspoint.com › home › cprogramming › c strings in c programming
C Strings in C Programming
June 10, 2012 - C - Pointers vs. Multi-dimensional Arrays ... 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.
🌐
Eskimo
eskimo.com › ~scs › cclass › notes › sx8.html
Chapter 8: Strings
The null or string-terminating character is represented by another character escape sequence, \0. (We've seen it once already, in the getline function of chapter 6.) Because C has no built-in facilities for manipulating entire arrays (copying them, comparing them, etc.), it also has very few built-in facilities for manipulating strings.
🌐
Go4Expert
go4expert.com › articles › strings-in-c-t29142
Strings in C | Go4Expert
Strings are paramount datatype for any real use case scenario. However, in C, there is no basic datatype as ‘string’. A string is understood as a...
🌐
CS UIC
cs.uic.edu › ~jbell › CourseNotes › C_Programming › CharacterStrings.html
C Programming Course Notes - Character Strings
The material in this page of notes is organized after "C Programming, A Modern Approach" by K.N. King, Chapter 13. Some content may also be from other sources. The C language does not have a specific "String" data type, the way some other languages such as C++ and Java do.
🌐
Codecademy
codecademy.com › docs › strings
C | Strings | Codecademy
April 21, 2025 - Strings in C are one-dimensional arrays of characters terminated by a null character '\0'. They are used to store and manipulate sequences of characters such as words or sentences in C programming.
🌐
Wikiversity
en.wikiversity.org › wiki › C_Programming › Strings
C Programming/Strings - Wikiversity
There is no string type in C. Instead we have arrays or constants, and we can use them to store sets of characters. The string "Hello World!" can be stored like in the example below · This creates an array of chars so that s[0] is 'H', s[1] is 'e', etc. In addition, because C allows us to ...
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Strings.html
Strings (GNU C Language Manual)
For instance, ... declares an array named ‘text’ with six elements—five letters and the terminating null character. An equivalent way to get the same result is this, ... declares an array long enough to hold a string of 199 ASCII characters plus the terminating null character.
🌐
Emory
cs.emory.edu › ~cheung › Courses › 255 › Syllabus › 2-C-adv-data › string.html
Strings in C --- arrays of char
String: array of characters or a (char *) We have just seen that a · string in C is stored as an · array of characters · Fact: Reason: Example: function with a · string variable · Example Program: (Demo above code) &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ·
🌐
WsCube Tech
wscubetech.com › resources › c-programming › strings
Strings in C Programming (Define, Declare, Initialize, Examples)
August 29, 2025 - Learn how to define, declare, and initialize strings in C programming with clear examples. Understand the basics of working with strings in C. Read now!