A string literal is an unnamed string constant in the source code. E.g. "abc" is a string literal.

If you do something like char str[] = "abc";, then you could say that str is initialized with a literal. str itself is not a literal, since it's not unnamed.

A string (or C-string, rather) is a contiguous sequence of bytes, terminated with a null byte.

A char array is not necessarily a C-string, since it might lack a terminating null byte.

Answer from HolyBlackCat on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - A string is an array of characters terminated by a special character '\0' (null character). This null character marks the end of the string and is essential for proper string manipulation.
🌐
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.
Discussions

What is a literal string & char array in C? - Stack Overflow
Firstly, I included C++ as C++ is just a parent of C, so I'm guessing both answers apply here, although the language I'm asking about and focusing on in this question is C, and not C++. So I began More on stackoverflow.com
🌐 stackoverflow.com
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
Can someone please tell me how to declare a string in C and read them with scanf()? Tutorials point/geekforgeeks/other internet resources are total garbage and hard to follow for beginners.
K&R is not intended to be a complete manual for every function in the C library: that's what man pages are for. K&R is a tutorial that introduces the C language (that is, the things that compilers deal with -- keywords, data types, syntax, ...), and shows some ways they can be connected together to make working programs. There are countless libraries that C can call: X-windows graphic libraries, and encryption libraries, and database access libraries, and networking libraries. They all come with their own manual pages. If the C Language book covered all those, then (a) you would not be able to lift it, and (b) it would be permanently out of date, as things evolve. My K&R is a First Edition from 1978, so the page numbering is not going to be the same as yours -- I'm not sure the section numbering will even be the same. That's why you use your own volume's index. Section 7.4 "Formatted Input" in mine covers scanf, 7.5 for sscanf, and 7.6 for fscanf. They are very similar, and use the same format "conversion specification" options: scanf reads from stdin, fscanf reads from a file, and sscanf reads from a string in memory. They work best for input where you are not too fussed about how it fits into input lines, so they are quite sloppy about whitespace. getline appears in section 1.9, as an example of how to write a function in C, and again in section 4.1 which is about how to structure a larger program. At the time, there was no standard library function getline(). When this was added into a library later, it was made to do the same kind of thing, but allows for expanding the input length automatically. So getline() reads a whole line from a file (which can be stdin or any other file or device), but it does not unpack any fields or values itself: there are a whole family of other functions that deal with those things. Some of those functions have names like strtok, strtol, strtod, and they all have man pages. Usually, there is a "See Also" section that links you into similar or related functions. fgets() is in section 7.8 "Line Input and Output" along with fputs(). fgets() is like getline, but simpler: you provide space for the string, but if it is too short you don't get a whole line of data, and you have to deal with that problem yourself. gets() is like fgets() but for stdin only. Also, it does not care at all about the space you provided for the input, and so can be misused to corrupt your program. The first four words in the man page are "Never use this function". All the code sections you posted are wrong, and here's why. char name[100000000]; reserves a buffer of 100 million characters as a local (on-stack) variable. That will use up all your stack and more besides, and your program won't run (probably not even load). char *x; would create a pointer to some chars, but it is not initialised to point to anywhere -- it is a pointer to something that does not exist. char **x; is even worse: is is a pointer to a pointer that does not exist, that would point to some chars that don't exist either. string x; uses a type "string" that does not exist in C. Some CS50 courses provide a header file that fixes up stuff like "string" to make your code easier to write, but they are not proper C and they hide the actual details, which is a piss-poor way to learn. scanf ("%c") reads exactly one character from the input. That is not a string. scanf ("%s") reads a string (like a name) from the input. It reads a real word: it skips any preceding whitespace, and it then only fetches text up to the next whitespace. Also, second example says #inclue and misses a ; off the scanf line, third one says scacnf, fourth one misses ; off scanf and a closing } . Compilers don't allow for carelessness. "string" is not part of the C language. It is verbal shorthand for "A row of text characters that ends with a zero (ASCII NUL) character. A row of things in C is usually called an array. To read and show a name in C, this would be good: #include int main(void) { char name [84]; //.. Allowing space for NUL terminator. printf("What's your name?\n"); scanf("%80s", name); //.. Limit field width on read. printf ("Good to meet you, %s!\n", name); } OK, I've spent 75 minutes writing this up. You need to do some work now. K&R is quite readable -- worth skimming the whole thing just to get an idea of what is in there -- get the shape of the language and fill in the detail later. Those dumb tutorials you found are mainly written for vanity by people who don't understand C themselves. 80% of it is junk. It really is worth reading enough man pages to understand why the information is presented like they do. More on reddit.com
🌐 r/C_Programming
28
0
April 18, 2021
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
Top answer
1 of 2
9

A string literal is an unnamed string constant in the source code. E.g. "abc" is a string literal.

If you do something like char str[] = "abc";, then you could say that str is initialized with a literal. str itself is not a literal, since it's not unnamed.

A string (or C-string, rather) is a contiguous sequence of bytes, terminated with a null byte.

A char array is not necessarily a C-string, since it might lack a terminating null byte.

2 of 2
6

What is a literal string & char array in C?

C has 2 kinds of literals: string literals and compound literals. Both are unnamed and both can have their address taken. string literals can have more than 1 null character in them.

In the C library, a string is characters up to and including the first null character. So a string always has one and only one null character, else it is not a string. A string may be char, signed char, unsigned char.

Copy//          v---v string literal 6 char long
char *s1 = "hello";
char *s2 = "hello\0world";
//          ^----------^  string literal 12 char long

char **s3 = &"hello";  // valid

//        v------------v  compound literal
int *p1 = (int []){2, 4};
int **p2 = &(int []){2, 4};  // vlaid 

C specifies the following as constants, not literals, like 123, 'x' and 456.7. These constants can not have their address taken.

Copyint *p3 = &7; // not valid

C++ and C differ in many of these regards.


A chararray is an array of char. An array may consist of many null characters.

Copychar a1[3];          // `a1` is a char array size 3
char a2[3] = "123";  // `a2` is a char array size 3 with 0 null characters 
char a3[4] = "456";  // `a3` is a char array size 4
char a4[] = "789";   // `a4` is a char array size 4
char a5[4] = { 0 };  // `a5` is a char array size 4, all null characters

The following t* are not char arrays, but pointers to char.

Copychar *t1;
char *t2 = "123";
int *t3 = (char){'x'};  
🌐
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.
🌐
Programiz
programiz.com › c-programming › c-strings
Strings in C (With Examples)
In C programming, a string is a sequence of characters terminated with a null character \0.
🌐
Codecademy
codecademy.com › docs › strings
C | Strings | Codecademy
April 21, 2025 - Strings in C are declared using the char data type, followed by the string name and square brackets []. String values can be initialized in two ways: Zero or more characters, digits, and escape sequences surrounded in double quotes. An array of comma-separated characters, surrounded in curly brackets {}, and ending with a null character '\0'. Note: The null character '\0' is important as it marks the end of the string.
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2014 › 01 › c-strings-string-functions
C – Strings and String functions with examples
It searches string str for character ch (you may be wondering that in above definition I have given data type of ch as int, don’t worry I didn’t make any mistake it should be int only. The thing is when we give any character while using strchr then it internally gets converted into integer for better searching.
🌐
Emory
cs.emory.edu › ~cheung › Courses › 255 › Syllabus › 2-C-adv-data › string.html
Strings in C --- arrays of char
String = a sequence of characters · Unlike Java, the C programming language does not have a String data type
🌐
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 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 of characters terminated by a special null character ('\0')....
🌐
Wikibooks
en.wikibooks.org › wiki › C_Programming › String_manipulation
C Programming/String manipulation - Wikibooks, open books for an open world
November 9, 2025 - The length of a string is determined by a terminating null character: '\0'. So, a string with the contents, say, "abc" has four characters: 'a', 'b', 'c', and the terminating null ('\0') character. The terminating null character has the value zero. ... In C, string constants (literals) are surrounded by double quotes ("), e.g.
🌐
Systems Encyclopedia
systems-encyclopedia.cs.illinois.edu › articles › c-strings
Strings in C - Systems Encyclopedia
While C does allow string literals, strings in C are strictly represented as character arrays terminated with a null byte (\0 or NUL). ... special case of character arrays; not all character arrays are considered strings, but any contiguous ...
🌐
Udemy
blog.udemy.com › home › c strings: the basics of creating, using, and updating strings in c
C Strings: The Basics of Creating, Using, and Updating Strings in C - Udemy Blog
July 30, 2021 - In C, a string is defined as an array of characters. A string array will always terminate with a special character, “\0.” Strings are frequently used and manipulated in C as a way of storing and printing text.
🌐
Substack
andrewjohnson4.substack.com › p › understanding-how-c-strings-are-stored
Understanding How C Strings Are Stored in the Data Section of a C Program
October 24, 2024 - When we declare a string in a C program, it can be either statically allocated or dynamically allocated. Statically allocated strings (like string literals) are stored in the Data segment, which is divided into two parts:
🌐
Yale University
cs.yale.edu › homes › aspnes › pinewiki › C(2f)Strings.html
C/Strings
Because delimited strings are more lightweight, C went for delimited strings. A string is a sequence of characters terminated by a null character '\0'. Note that the null character is not the same as a null pointer, although both appear to have the value 0 when used in integer contexts.
🌐
BYJUS
byjus.com › gate › string-in-c-notes
String in C Notes for GATE
August 1, 2022 - A string in C is like an array of characters, pursued by a NULL character.
🌐
The Valley of Code
thevalleyofcode.com › lesson › c-advanced › return-string
C Advanced: Returning strings
Note the use of const, because from the function I’m returning a string literal, a string defined in double quotes, which is a constant.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › cpp › string-and-character-literals-cpp
String and character literals (C++) | Microsoft Learn
March 24, 2025 - A string literal represents a sequence of characters that together form a null-terminated string. The characters must be enclosed between double quotation marks. There are the following kinds of string literals: A narrow string literal is a ...
🌐
mbedded.ninja
blog.mbedded.ninja › programming › languages › c › string-manipulation-in-c
String Manipulation in C | mbedded.ninja
January 31, 2024 - Strings in C are represented by either a pointer to char char* myStr or array of char char myStr[10]. What is laid out in memory is a series of byte sized ASCII encoded characters, terminated by the null character ('\0' or 0x00).