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)
Write a function to check if a given string is empty or not. Return 1 if the string is empty, otherwise, return 0. For example, if str = "Hello", the expected output is 0
๐ŸŒ
w3resource
w3resource.com โ€บ c-programming-exercises โ€บ string โ€บ index.php
C programming exercises: String - w3resource
Test Data : Check the length of two strings: -------------------------------- Input the 1st string : aabbcc Input the 2nd string : abcdef String1: aabbcc String2: abcdef Expected Output : Strings are not equal.
Discussions

Does C have a string type? - Stack Overflow
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 ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
Nylon strings to play in Drop C
this doesnt really work. nylon strings arent as responsive/ loud as steel strings, so tuning any set down that far will make the strings very very loose, and they wont play well, or loud enough. however, dont put steel strings on your classical guitar! More on reddit.com
๐ŸŒ r/classicalguitar
9
1
December 22, 2018
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
June 30, 2009
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ strings
C | Strings | Codecademy
April 21, 2025 - Even though โ€œHowdyโ€ has only 5 characters, message has 6 characters due to the null character at the end of the array. ... To display a string in C, the printf() function from the stdio.h header file can be used along with the %s format specifier:
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_strings_functions.php
C String Functions
Note that the size of str2 should be large enough to store the copied string (20 in our example).
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.

๐ŸŒ
George Washington University
www2.seas.gwu.edu โ€บ ~bell โ€บ csci1121 โ€บ lectures โ€บ strings.pdf pdf
Abdelghani Bellaachia, CSCI 1121 Page: 1 C Strings 1.
String Declaration & Initialization ............................... 2 ... Note: Ask the user for the abbreviation. ๏‚ท Write a C program that implements that stores roster
๐ŸŒ
Learn C
learnc.net โ€บ home โ€บ learn c programming โ€บ c string
C String
April 13, 2025 - But when you define a string, you must reserve one element in the array to store the null character. Itโ€™s important to notice that the null character is different from the the NULL pointer constant. The following example defines a string with 6 characters (including the null character), assigns ...
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ learn_c_by_examples โ€บ string_programs_in_c.htm
String Programs in C
Strings are actually one-dimensional array of characters terminated by a null character '\0'. Thus a null-terminated string contains the characters that comprise the string followed by a null. The following declaration and initialization create a string consisting of the word "Hello".
๐ŸŒ
Sanfoundry
sanfoundry.com โ€บ c-programming-examples-strings
String Programs in C - Sanfoundry
May 19, 2023 - The following section contains ... recursion, frequency, and occurrence of characters in a string. C programs on string matching, approximate string matching, and encryption algorithms are also covered with examples....
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ cprogramming โ€บ c strings in c programming
C Strings in C Programming
June 10, 2012 - You can loop through a string (character array) to access and manipulate each character of the string using the for loop or any other loop statements. In the following example, we are printing the characters of the string.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_strings.php
C Strings
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. Instead, you must use the char type and create an array of characters to make a string ...
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ strings in c | initialization and string functions (+examples)
Strings In C | Initialization and String Functions (+Examples)
May 30, 2025 - Let's get started! A string is a sequence of characters belonging to a specific character set. For example, "hello world" is a string containing five characters: "h," "e", "l", "l", and "o".
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-print-a-string-in-c
C Print String โ€“ How to Print a String in C
April 17, 2024 - Creating non-null-terminated strings intentionally is not common in C. Here is an example of a non-null-terminated string: char greeting[] = {'H', 'e', 'l', 'l', 'o'};This array of characters does not include the null terminator, \0, so it is ...
๐ŸŒ
CS UIC
cs.uic.edu โ€บ ~jbell โ€บ CourseNotes โ€บ C_Programming โ€บ CharacterStrings.html
C Programming Course Notes - Character Strings
Note that many of the concepts covered in this section also apply to other situations involving combinations of arrays, pointers, and functions. A String Literal, also known as a string constant or constant string, is a string of characters enclosed in double quotes, such as "To err is human - To really foul things up requires a computer."
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - To find the length of a string in C, you need to iterate through each character until you reach the null terminator '\0', which marks the end of the string. 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.
๐ŸŒ
Systems Encyclopedia
systems-encyclopedia.cs.illinois.edu โ€บ articles โ€บ c-strings
Strings in C - Systems Encyclopedia
In C, buffer overflows from strings are typically the result of misuse of standard library functions. For example, buffer overflows occur when strcpy or strcat are used on under-allocated strings.
๐ŸŒ
ScholarHat
scholarhat.com โ€บ home
Strings in C with Examples: String Functions
August 2, 2025 - Explanation: The strcat() function in C is used to concatenate (append) one string to another. For example, strcat(dest, src); appends src to dest.
๐ŸŒ
Weber State University
icarus.cs.weber.edu โ€บ ~dab โ€บ cs1410 โ€บ textbook โ€บ 8.Strings โ€บ c_string_funcs.html
8.2.2. C-String Documentation And Functions
In the C-string library functions, nullptr may appear as either an argument or as a return value. But what it means depends on the specific function. For example, when a function returns nullptr, it may indicate an error has occurred; if the function is processing data, it may mean that all data is processed; or in the case of a searching function, it may indicate the search didn't find what it was looking for.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ String_(computer_science)
String (computer science) - Wikipedia
January 25, 2026 - The length of the string in the above example, "FRANK", is 5 characters, but it occupies 6 bytes. Characters after the terminator do not form part of the representation; they may be either part of other data or just garbage.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ strings input and output functions in c
Strings Input and Output functions in C
November 16, 2023 - So far, gets() seems to be a great method to take string input in C with spaces. But gets() doesn't care about the size of the character array passed to it. This means, in the above example, if the user input would be more than 30 characters long, the gets() function would still try to store it in the sentence[] array, but as there is not much available space, this would lead to buffer overflow.