🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_strings.htm
Strings in C
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.
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_array_of_strings.htm
Array of Strings in C
C - Pointers vs. Multi-dimensional Arrays ... In C programming language, a string is an array of character sequences terminated by NULL, it is a one-dimensional array of characters.
Discussions

How do I create an array of strings in C? - Stack Overflow
This assumes the size and number ... array dimensions. In this case, the contents of each string literal (which is itself a zero-terminated array of char) are copied to the memory allocated to strs. The problem with this approach is the possibility of internal fragmentation; if you have 99 strings that are 5 characters or less, but ... More on stackoverflow.com
🌐 stackoverflow.com
What are Strings in C if not Simply Char Arrays? - Stack Overflow
I'm new to the C programming language, and I was under the impression that strings are just arrays of characters. However, when I tried the following code below (among some other tests): #include More on stackoverflow.com
🌐 stackoverflow.com
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
57
10
November 3, 2024
So why aren't strings considered arrays?
Strings are character arrays in most languages... More on reddit.com
🌐 r/learnprogramming
22
4
November 30, 2020
🌐
GeeksforGeeks
geeksforgeeks.org › c language › array-of-strings-in-c
Array of Strings in C - GeeksforGeeks
July 23, 2025 - In C, an array of strings is a 2D array where each row contains a sequence of characters terminated by a '\0' NULL character (strings).
🌐
Scaler
scaler.com › home › topics › what is an array of strings in c?
What is an Array of Strings in C? - Scaler Topics
April 30, 2024 - In C, an array represents a linear collection of data elements of a similar type. Thus, an array of strings means a collection of several strings. The string is a one-dimensional array of characters terminated with the null character.
🌐
GUVI
guvi.in › hub › c-tutorial › string-and-character-array
Strings and Character Arrays in C Language
String is a sequence of characters ... the C language does not support strings as a data type. A string is actually a one-dimensional array of characters in C language....
🌐
W3Schools
w3schools.com › c › c_strings.php
C Strings
Instead, you must use the char ... = "Hello World!"; printf("%s", greetings); Try it Yourself » · Since strings are actually arrays in C, you can access a string by referring to its index number inside square brackets ...
🌐
Tutorialink
tutorialink.com › home › c language › string and character array
String and Character array | C Language | Tutorialink.com
string is a sequence of characters that is treated as a single data item and terminated by null character'\0'. Remember that C language does not support strings as a data type. A string is actually one-dimensional array of characters in C language.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
3 weeks ago - The null character '\0' marks the end of the string. C does not have a built-in string data type. Strings are implemented using arrays of char.
Find elsewhere
Top answer
1 of 15
306

If you don't want to change the strings, then you could simply do

const char *a[2];
a[0] = "blah";
a[1] = "hmm";

When you do it like this you will allocate an array of two pointers to const char. These pointers will then be set to the addresses of the static strings "blah" and "hmm".

If you do want to be able to change the actual string content, the you have to do something like

char a[2][14];
strcpy(a[0], "blah");
strcpy(a[1], "hmm");

This will allocate two consecutive arrays of 14 chars each, after which the content of the static strings will be copied into them.

2 of 15
251

There are several ways to create an array of strings in C. If all the strings are going to be the same length (or at least have the same maximum length), you simply declare a 2-d array of char and assign as necessary:

char strs[NUMBER_OF_STRINGS][STRING_LENGTH+1];
...
strcpy(strs[0], aString); // where aString is either an array or pointer to char
strcpy(strs[1], "foo");

You can add a list of initializers as well:

char strs[NUMBER_OF_STRINGS][STRING_LENGTH+1] = {"foo", "bar", "bletch", ...};

This assumes the size and number of strings in the initializer match up with your array dimensions. In this case, the contents of each string literal (which is itself a zero-terminated array of char) are copied to the memory allocated to strs. The problem with this approach is the possibility of internal fragmentation; if you have 99 strings that are 5 characters or less, but 1 string that's 20 characters long, 99 strings are going to have at least 15 unused characters; that's a waste of space.

Instead of using a 2-d array of char, you can store a 1-d array of pointers to char:

char *strs[NUMBER_OF_STRINGS];

Note that in this case, you've only allocated memory to hold the pointers to the strings; the memory for the strings themselves must be allocated elsewhere (either as static arrays or by using malloc() or calloc()). You can use the initializer list like the earlier example:

char *strs[NUMBER_OF_STRINGS] = {"foo", "bar", "bletch", ...};

Instead of copying the contents of the string constants, you're simply storing the pointers to them. Note that string constants may not be writable; you can reassign the pointer, like so:

strs[i] = "bar";
strs[i] = "foo"; 

But you may not be able to change the string's contents; i.e.,

strs[i] = "bar";
strcpy(strs[i], "foo");

may not be allowed.

You can use malloc() to dynamically allocate the buffer for each string and copy to that buffer:

strs[i] = malloc(strlen("foo") + 1);
strcpy(strs[i], "foo");

BTW,

char (*a[2])[14];

Declares a as a 2-element array of pointers to 14-element arrays of char.

Top answer
1 of 1
4

In these declarations

char apple1[] = { 'a', 'p', 'p', 'l', 'e', '\0' };
char *apple2 = "apple";
char apple3[] = "apple";

there are declared two arrays apple1 and apple3 that contain the string "apple".

In this declaration

char *apple2 = "apple";

there is declared a pointer to the string literal "apple".

In these calls of printf

printf("%i\n", apple1 == apple2); // 0
printf("%i\n", apple2 == apple3); // 0
printf("%i\n", apple3 == apple1); // 0
printf("%i\n", "apple" == apple1); // 0
printf("%i\n", "apple" == apple2); // 1
printf("%i\n", "apple" == apple3); // 0

there are compared addresses of first characters of different arrays that occupy different extents of memory. Arrays used in expressions with rare exceptions are converted to pointers to their first elements. So the result of the expressions is the integer value 0 except this call

printf("%i\n", "apple" == apple2); // 1

because in this case there are compared pointers to the same string literal (its first character) because it seems the compiler allocated one character array to store the string literal "apple" used in this call and in this declaration of a pointer

char *apple2 = "apple";

You can represent the above declaration and the call of printf the following way

char *apple2 = &"apple"[0];
//...
printf("%i\n", &"apple"[0] == apple2); // 1

However in general even if you will write for example

printf("%i\n", "apple" == "apple");

then the output can be either 0 or 1 depending on how the compiler stores identical string-literals: either as different character arrays or as one character array (it depends on compiler options).

To compare character arrays that contain strings you need to use standard C string function strcmp.

🌐
Quora
quora.com › How-is-a-one-dimensional-character-array-and-a-string-similar
How is a one-dimensional character array and a string similar? - Quora
Answer (1 of 6): Strings The Plain English programming language (my favorite) stores strings in two parts, like this: (The addresses above are fictitious, of course.) The string’s anchor, shown on the left, may be a global variable (stored in the program’s Data Section, or a local variable (all...
🌐
GeeksforGeeks
geeksforgeeks.org › c language › one-dimensional-arrays-in-c
One Dimensional Arrays in C - GeeksforGeeks
July 23, 2025 - The strings are essentially an array of character that is terminated by a NULL character ('\0').
🌐
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.
🌐
Studytonight
studytonight.com › c › string-and-character-array.php
String and Character Arrays in C Language | Studytonight
String is a sequence of characters that are treated as a single data item and terminated by a null character '\0'. Remember that the C language does not support strings as a data type. A string is actually a one-dimensional array of characters in C language.
🌐
Steve's Data Tips and Tricks
spsanderson.com › steveondata › posts › 2024-10-02
Understanding Character Variables in C: A Beginner’s Guide – Steve's Data Tips and Tricks
October 2, 2024 - In C, a string is defined as a one-dimensional array of characters, terminated by a null character (‘\0’).
🌐
CS UIC
cs.uic.edu › ~jbell › CourseNotes › C_Programming › CharacterStrings.html
C Programming Course Notes - Character Strings
String literals are stored in C as an array of chars, terminted by a null byte. A null byte is a char having a value of exactly zero, noted as '\0'. Do not confuse the null byte, '\0', with the character '0', the integer 0, the double 0.0, or the pointer NULL.