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
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ array-of-strings-in-c
Array of Strings in C - GeeksforGeeks
July 23, 2025 - It is used to store multiple strings in a single array. ... #include <stdio.h> int main() { // Creating array of strings for 3 strings // with max length of each string as 10 char arr[3][10] = {"Geek", "Geeks", "Geekfor"}; for (int i = 0; i ...
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.

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ cprogramming โ€บ c array of strings
C Array of Strings
June 10, 2012 - In the following example, we store the length of first string and its position (which is "0") in the variables "l" and "p" respectively. Inside the for loop, we update these variables whenever a string of larger length is found.
๐ŸŒ
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 - As mentioned in the code comment, ... function in detail in a later section. After that, we use a for loop to print the elements of the string array to the console....
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2806362 โ€บ how-to-loop-through-a-string-array-in-c
How to loop through a string array in C? | Sololearn: Learn to code for FREE!
My attempt: #include <stdio.h> #include <string.h> int main() { char full_name[] = "Drex Holmes"; for (int i = 0; i < full_name.length; i++) { printf("%s", i); } return 0; } ... Use strlen() to get the length of the string.
๐ŸŒ
Learning Monkey
learningmonkey.in โ€บ home โ€บ array of strings in c
Array of Strings in C Detailed Explanation Made Easy Lec-70 - Learning Monkey
July 24, 2021 - To access a character in the string, we have to use both row and column numbers. In the above example, we have initialized the array, but we will allow the user to enter the details in this example. The image below is the program to understand. ... The first for loop in the above example is to allow the user to give the string inputs.
๐ŸŒ
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 - Subsequently, we loop in a nested manner, in which the outer loop accesses the array item, and the inner loop prints the characters of that string until the end. Several functions help us while manipulating strings in C. Some of them are described ...
Find elsewhere
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ c-iterating-string-array-with-c-while-loop-136081
C Programming | Iterate List of Strings with While Loop | LabEx
Learn how to iterate through a list of strings using a while loop in C programming. Explore an example that prints each string in an array until the end of the list.
๐ŸŒ
Wikibooks
en.wikibooks.org โ€บ wiki โ€บ C_Programming โ€บ Arrays_and_strings
C Programming/Arrays and strings - Wikibooks, open books for an open world
August 11, 2003 - During program execution, an out of bounds array access does not always cause a run time error. Your program may happily continue after retrieving a value from point[-1]. To alleviate indexing problems, the sizeof() expression is commonly used when coding loops that process arrays.
๐ŸŒ
Log2Base2
log2base2.com โ€บ C โ€บ string โ€บ array-of-string.html
Array of strings in c
#include<stdio.h> int main() { /* *total 5 strings *each string can at max 20 char long. */ char subject[5][20]={"Tamil","English","Maths","Science","Social Science"}; int i; //printing each string for(i = 0; i < 5; i++) printf("%s\n",subject[i]); return 0; } Run it ยท Getting array of string input from the user and print it.
๐ŸŒ
OverIQ
overiq.com โ€บ c-programming-101 โ€บ array-of-strings-in-c
Array of Strings in C - C Programming Tutorial - OverIQ.com
What is an Array of Strings? # A string is a 1-D array of characters, so an array of strings is a 2-D array of characters. Just like we can create aโ€ฆ
๐ŸŒ
Medium
medium.com โ€บ @divyasrdj โ€บ programming-in-c-arrays-strings-1695160875a3
Programming in C โ€” Arrays & Strings | by Divya Stephen | Medium
June 16, 2025 - :) To create an array, define the data type (like int) and specify the name of the array followed by square brackets []. To insert values to it, use a comma-separated list inside curly braces, and make sure all values are of the same data type: ...
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ c-create-string-array-iterators-in-c-438245
Create String Array Iterators in C | LabEx
Learn how to declare, iterate, and print string arrays in C using while loops, focusing on null-terminated string handling and array traversal techniques.
๐ŸŒ
DEV Community
dev.to โ€บ missmati โ€บ pointers-arrays-strings-in-c-52h3
Pointers , Arrays & Strings in C - DEV Community
October 11, 2022 - Based on how you want to represent ... code, ... ** To access the string array, we need to create a pointer to the array and initialize the pointer with the array....
๐ŸŒ
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!
๐ŸŒ
LabEx
labex.io โ€บ questions โ€บ how-to-print-each-element-of-a-c-string-array-136081
How to Print Each Element of a C String Array in C | LabEx
July 25, 2024 - In this example, we first calculate ... by the size of a single element. Then, we use a for loop to iterate through the array and print each string using the printf() function....
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 88153-how-pass-array-strings-function-argument.html
How to pass an array of strings as a function argument?
size_t stringNbr = 10; size_t maxStringLength = 128; int i; char **myStringArray; myStringArray = malloc(stringNbr * sizeof(char *)); for (i = 0; i < stringNbr; i++) { myStringArray[i] = malloc(maxStringLength * sizeof(char)); } As you can see, I first allocate space for "stringNbr" pointers ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - We can change individual characters of a string using their index: str[0] = 'h'. Strings can also be updated using standard library functions like strcpy() to replace the entire string.
๐ŸŒ
Tpoint Tech
tpointtech.com โ€บ an-array-of-strings-in-c
An Array of Strings in C - Tpoint Tech
An Array is the simplest Data Structure in C that stores homogeneous data in contiguous memory locations. If we want to create an Array, we declare the Data ...