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
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.

🌐
Northern Illinois University
faculty.cs.niu.edu › ~mcmahon › CS241 › Notes › cstrings.html
C Strings
Similarly, a member function of a class may return a C string data member of that class. In all cases, the string is returned by address, and the data type should be coded as char* or const char*. Trying to return a C string declared as a local variable of a function will produce a warning (and won't work).
Discussions

Does c have strings
You’re just having an argument over what the definition of “string” is. Your argument has nothing to do with C. It’s what people are talking about when they say “arguing over semantics”. These arguments, where you both agree about what the truth is (you agree how C works), but you disagree over the semantics of the words you use to describe C (you disagree about what a “string” is). The C standard is not going to decide this argument for you. Neither is the dictionary. More on reddit.com
🌐 r/cprogramming
55
10
November 3, 2024
New to C. If C does not have strings, then what exactly is printf doing?
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. More on reddit.com
🌐 r/C_Programming
34
66
January 26, 2022
The Complete Guide to Building Strings In C++
The article is not bad if you remove the cheap jabs at printf. Using Boost to build strings is just overengineering and seems to be added to the article just to make it more clickbaity. More on reddit.com
🌐 r/programming
26
17
September 18, 2017
In your opinions, what is wrong with the C language? What did they do poorly, etc?
The problem with C is when people want to compare it with higher-level languages. This simply has no point. If you find yourself thinking "crap, C has no GC!", "C hasn't a full blown type system!" or something like that, then you're not using the right tool for your task. More on reddit.com
🌐 r/programming
687
54
July 19, 2009
People also ask

How to compare two strings in C program?
Use strcmp(str1, str2); It returns 0 if strings are equal.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › strings
Strings in C Programming (Define, Declare, Initialize, Examples)
How to concatenate two strings in C programming?
Use strcat(str1, str2); to append str2 to str1.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › strings
Strings in C Programming (Define, Declare, Initialize, Examples)
🌐
George Washington University
www2.seas.gwu.edu › ~bell › csci1121 › lectures › strings.pdf pdf
Abdelghani Bellaachia, CSCI 1121 Page: 1 C Strings 1.
 A string in C is nothing but an array of type char ·  Two ways to declare a variable that will hold a · string of characters: o Using arrays: char mystr[6] = {'H', 'e', 'l', 'l', 'o', '\0'}; Abdelghani Bellaachia, CSCI 1121 · Page: 3 · o Using a string of characters: char mystr [] ...
🌐
W3Schools
w3schools.com › c › c_strings.php
C Strings
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 ...
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › home › cprogramming › c strings in c programming
C Strings in C Programming
June 10, 2012 - Let us create a string "Hello". It comprises five char values. 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.
🌐
Programiz
programiz.com › c-programming › c-strings
Strings in C (With Examples)
In this tutorial, you'll learn about strings in C programming. You'll learn to declare them, initialize them and use them for various I/O operations with the help of examples.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - A string is an array of characters ... essential for proper string manipulation. Unlike many modern languages, C does not have a built-in string data type....
🌐
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!
🌐
Scaler
scaler.com › home › topics › c strings - declaring strings in c
C Strings | Declaring Strings in C - Scaler Topics
December 21, 2023 - C does not directly support string as a data type, as seen in other programming languages like C++. Hence, character arrays must be used to display a string in C. The general syntax of declaring a string in C is as follows:
🌐
Unstop
unstop.com › home › blog › strings in c | initialization and string functions (+examples)
Strings In C | Initialization and String Functions (+Examples)
May 30, 2025 - We create an empty character array of size 20 and assign it to the variable 'str' with char str[20]. Next, when the user enters their name, it is stored in the "str" variable. This value is then printed on the screen using printf(). The return 0 statement at the end indicates that this program has run successfully. We use the character data type to declare a string in C, and the syntax is the same as mentioned above.
🌐
CS UIC
cs.uic.edu › ~jbell › CourseNotes › C_Programming › CharacterStrings.html
C Programming Course Notes - Character Strings
parses a string of numeric characters into a number of type int, double, long int, or long long int, respectively.
🌐
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).
🌐
freeCodeCamp
freecodecamp.org › news › c-string-how-to-declare-strings-in-the-c-programming-language
C String – How to Declare Strings in the C Programming Language
October 6, 2021 - As you see, there is no built-in string or str (short for string) data type. From those types you just saw, the only way to use and present characters in C is by using the char data type.
🌐
ScholarHat
scholarhat.com › home
Strings in C with Examples: String Functions
August 2, 2025 - Explanation: The strlen() function in C calculates the length of a string (excluding the null character) and returns the result as an integer. Strings are a type of character array with a null terminator (\0) to signify the end of the string.
🌐
W3Schools
w3schools.com › c › c_ref_string.php
C string (string.h) Library Reference
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 ... The <string.h> library has many functions that allow you to perform tasks on strings. A list of all string functions can be found in the table below:
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › csharp › programming-guide › strings
Strings - C# | Microsoft Learn
You can try signing in or changing directories. Access to this page requires authorization. You can try changing directories. ... A string is an object of type String whose value is text. Internally, the text is stored as a sequential read-only collection of Char objects.
🌐
Florida State University
cs.fsu.edu › ~myers › cop3330 › notes › strings.html
C-strings vs. strings as objects
Recall that a C-string is implemented as a null-terminated array of type char · No built-in string type in C.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › string-functions-in-c
C String Functions - GeeksforGeeks
July 26, 2025 - C language provides various built-in functions that can be used for various operations and manipulations on strings. These string functions make it easier to perform tasks such as string copy, concatenation, comparison, length, etc. The <string.h> header file contains these string functions. The strlen() function is used to find the length of ...