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.

Answer from Mikael Auno on Stack Overflow
🌐
Unstop
unstop.com › home › blog › string array in c | a complete explanation (+code examples)
String Array In C | A Complete Explanation (+Code Examples)
March 19, 2024 - A string array or an array of strings in C is a two-dimensional array that contains strings as elements. They help in manipulating textual data with ease.
Top answer
1 of 15
305

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.

Discussions

how do I assign a string to an array in C?
char myarr[10][0]; This line is going to be a problem. It is allocating ten zero byte arrays. You can't store any data in this variable. Can you describe in English what you want to be able to do with myarr? More on reddit.com
🌐 r/learnprogramming
5
2
November 9, 2020
Build an fCC Forum Leaderboard - Build an fCC Forum Leaderboard
Tell us what’s happening: i need more explanation about this lab, this is my fourth day on this issue, have try my possible best but i cant figure the proplem’ kindly help me please. these are the instruction” 1 You should have a function named timeAgo that takes a single argument. More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
2 weeks ago
Is it possible to get sizeof string in array of string literals?
No, you cannot use the sizeof operator for this. The sizeof operator works entirely off the type of its operand. Indeed, this is pretty much why the operator can also be used directly on a type. But there's nothing in the type of strarray that says what the length of those strings are. The type of this object is "3-element array of pointer to constant character", so the only things sizeof has to work on are "3", "pointer" and "character"... which is why you got those results when you used it on various parts of strarray. More on reddit.com
🌐 r/C_Programming
19
2
May 19, 2020
[Caesar]How to declare an empty string array in C?
First, you should realize that the caesar and vigenere problems don't require you to create an encrypted string for later printing. You can print the result of encrypting each character as you go. Your declaration of c_txt is trying to create an array of i strings. What you could do is compute the length (call it p_len, for example) of the p_txt string, and then define an array whose element type is char and whose dimension is p_len + 1. The extra element is to allow for a null character ('\0') after the encrypted string. That null terminating character is needed if you intend to print the string using printf. More on reddit.com
🌐 r/cs50
2
3
April 26, 2014
🌐
Silicon Cloud
silicloud.com › home › how do you declare an array of strings in the c language?
How do you declare an array of strings in the C language? - Blog - Silicon Cloud
March 21, 2024 - Using an array of characters: char strArray[10]; // 声明一个有10个元素的字符数组 “Using an array of pointers:” char *strArray[10]; // 声明一个有10个指针元素的数组 When declaring a string array using an array of pointers, make sure to allocate memory space for each ...
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-arrays
Arrays in C - GeeksforGeeks
In this case, the remaining elements will be assigned the value 0 (or equivalent according to the type). Array in C provides random access to its elements, which means that we can access any element of the array by providing the position of the element, called the index.
Published   October 17, 2025
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › home › cprogramming › c array of strings
C Array of Strings
June 10, 2012 - To declare an array of strings, you need to declare a two-dimensional array of character types, where the first subscript is the total number of strings and the second subscript is the maximum size of each string.
🌐
W3Schools
w3schools.com › c › c_strings.php
C Strings
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 in C:
Find elsewhere
🌐
LabEx
labex.io › questions › how-to-declare-an-array-of-strings-in-c-136081
How to Declare an Array of Strings in C | LabEx
July 25, 2024 - ## Declaring an Array of Strings in C In the C programming language, you can declare an array of strings by creating an array of character pointers.
🌐
Quora
quora.com › How-can-I-declare-an-array-of-strings-in-C-an-example-would-be-helpful
How to declare an array of strings in C (an example would be helpful) - Quora
Answer (1 of 6): While you could create a two-dimensional array of characters, where each row of the array is the beginning of a new string, this approach artificially limits the length of the strings in the array (the limit is the number of columns in the array minus one, for the null-terminatio...
🌐
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).
🌐
Aticleworld
aticleworld.com › home › array of strings in c
Array of Strings in C - Aticleworld
February 26, 2023 - You can read this article, “C String Literals with Its Types“. ... In the above example, str is the name of a 1d array.
🌐
LinkedIn
linkedin.com › pulse › what-arrays-strings-c-programming-mary-ng-ang-a
What are Arrays and Strings in C programming?
... #include <stdio.h> int main() ... the third element of the array return 0; } A string is a sequence of characters that is terminated by a null character ('\0')....
🌐
YouTube
youtube.com › playlist
Array and Strings in C Programming - YouTube
Hello guys , in this series of videos I had covered every aspects of arrays and strings in c programming language . I had given multiple examples throughout ...
🌐
Medium
medium.com › software-test-automation-by-rr › understanding-arrays-and-strings-in-c-programming-1944d1abbca1
Understanding Arrays and Strings in C Programming | by Rajasekar R | DevLab | Medium
December 16, 2024 - In this article, you’ll learn how to work with collections of data (arrays) and manipulate strings (character arrays) in C. Arrays and…
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Build an fCC Forum Leaderboard - Build an fCC Forum Leaderboard
2 weeks ago - Tell us what’s happening: i need more explanation about this lab, this is my fourth day on this issue, have try my possible best but i cant figure the proplem’ kindly help me please. these are the instruction” 1 You should have a function named timeAgo that takes a single argument.
🌐
W3Schools
w3schools.com › c › c_arrays.php
C Arrays
C Examples C Real-Life Examples ... Q&A C Certificate ... Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value....
🌐
Scribd
scribd.com › document › 840667677 › Arrays-and-Strings-Arrays-and-Strings-Cheatsheet
Understanding C Arrays and Strings | PDF
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
WsCube Tech
wscubetech.com › resources › c-programming › array-of-strings
Array of Strings in C Language (With Examples)
November 10, 2025 - Learn how to create and use an array of strings in C programming. Explore different methods and operations with examples, output, and explanations. Read now!
🌐
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.