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
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - But in C, strings can also be represented using string literals, which offer a simpler way to initialize strings directly in the code. Let's understand what string literals are and how they work. A string literal is a sequence of characters enclosed in double quotes, like "Hello" or "1234".
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).

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
🌐
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 ...
🌐
Wikipedia
en.wikipedia.org › wiki › C_string_handling
C string handling - Wikipedia
December 9, 2025 - This was recognized as a defect ... add two types with explicit widths char16_t and char32_t. Variable-width encodings can be used in both byte strings and wide strings. String length and offsets are measured in bytes or wchar_t, not in "characters", which can be confusing to beginning programmers...
🌐
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.
Find elsewhere
🌐
CS UIC
cs.uic.edu › ~jbell › CourseNotes › C_Programming › CharacterStrings.html
C Programming Course Notes - Character Strings
The methods stricmp and strnicmp do case-insensitive comparisons, but may be available for C++ programs only. parses a string of numeric characters into a number of type int, double, long int, or long long int, respectively.
🌐
Codecademy
codecademy.com › docs › strings
C | Strings | Codecademy
April 21, 2025 - strchr() - Finds the first occurrence of a given character. strcmp() - Compares two strings and returns an integer value. ... In C, there is only one type of string: a null-terminated array of characters.
🌐
Northern Illinois University
faculty.cs.niu.edu › ~mcmahon › CS241 › Notes › cstrings.html
C Strings
The destination array must be large enough to hold the combined strings (including the null character). If it is not, the array will overflow. Regardless of how a C string is declared, when you pass the string to a function, the data type of the string can be specified as either char[] (array of char) or char* (pointer to char).
🌐
TutorialsPoint
tutorialspoint.com › home › cprogramming › c strings in c programming
C Strings in C Programming
June 10, 2012 - 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.
🌐
BYJUS
byjus.com › gate › string-in-c-notes
String in C Notes for GATE
August 1, 2022 - strchr(s1, ch); – It is used to discover the foremost event or occurrence of a specified character within the actual string. strstr(s1, s2); – It is used to return a pointer to a character at the first index ... By using the null character. ... Q. Consider the following C program.
🌐
Programiz
programiz.com › c-programming › c-string-examples
String Examples in C Programming
Contains various examples of strings in C programming: Source Code to find frequency of character in a sentence, calculate number of vowels, consonants, space etc in a sentence, reverse string, sort words in dictionary order...
🌐
Unstop
unstop.com › home › blog › strings in c | initialization and string functions (+examples)
Strings In C | Initialization and String Functions (+Examples)
May 30, 2025 - In the world of C programming, a string is more than just a sequence of characters—it's a fundamental concept that allows developers to work with textual data. Unlike many modern programming languages that offer built-in string types with extensive functionality, C handles strings as arrays ...
🌐
Upgrad
upgrad.com › home › blog › software development › top 9 popular string functions in c with examples every programmer should know in 2025
The Ultimate Cheat Sheet: 9 Popular String Functions in C
June 16, 2025 - Each type has its use cases, with fixed-size strings being simple and efficient, while dynamic strings offer flexibility in memory allocation. Functions in C are blocks of reusable code designed to perform specific tasks. They help improve modularity, readability, and efficiency in programming.
🌐
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
🌐
ScholarHat
scholarhat.com › home
Strings in C with Examples: String Functions
August 2, 2025 - In C programming language, several string functions canbe used to manipulate strings. To use them, you must include the <string.h> header file in your program. Here are some of the commonly used string functions in C:
🌐
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.
🌐
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 ...
🌐
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!