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
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.

🌐
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).
Discussions

How would I make a array of strings in C? - 39. C Strings - Big Nerd Ranch Book Forums
I’m attempting to make a array of strings in C. If I use this code: char (*a[2])[14]; a[0]="blah"; a[1]="hmm"; gcc gives me “warning: assignment from incompatible pointer type”. What is the right method for doing this? More on forums.bignerdranch.com
🌐 forums.bignerdranch.com
0
June 26, 2022
c - Dynamically create an array of strings with malloc - Stack Overflow
I am trying to create an array of strings in C using malloc. The number of strings that the array will hold can change at run time, but the length of the strings will always be consistent. I've More on stackoverflow.com
🌐 stackoverflow.com
Difference between strings and character arrays in C?
There is no such thing as a string type in C. By convention, strings are represented as null-terminated character arrays. Many string functions will do undefined behavior if the null terminator is missing. More on reddit.com
🌐 r/learnprogramming
21
3
August 29, 2017
Qsort a 2d array of strings.
'ar' is an array with 4 elements, and C arranges these in memory sequentially, which is what qsort is expecting. ptr is only long enough to hold two elements, and you are telling qsort that it has 4. It doesn't understand this whole pointers-to-pointers-to-pointers structure you are attempting to use. Try treating ptr as a single dimensional array, and doing the subscript lookup math yourself. More on reddit.com
🌐 r/C_Programming
5
2
June 29, 2018
People also ask

Can I sort an array of strings in C?
Yes, use strcmp() to compare strings and strcpy() to swap them in a sorting algorithm like bubble sort.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › array-of-strings
Array of Strings in C Language (With Examples)
How can I take user input for an array of strings in C?
Use a 2D array and loop through it with scanf() or fgets() to take input for each string.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › array-of-strings
Array of Strings in C Language (With Examples)
How do I compare strings in an array?
Use strcmp(arr[i], arr[j]) to compare two strings. It returns 0 if the strings are equal.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › array-of-strings
Array of Strings in C Language (With Examples)
🌐
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:
🌐
Medium
medium.com › @mdsiaofficial › array-of-strings-in-c-programming-fd5755ccd3f8
Array of Strings in C programming | by Md Shoriful Islam Ashiq | Medium
April 2, 2024 - #include<stdio.h> #include<stdlib.h> #include<string.h> int main(){ char s[MAX_NAME] = "Ashiq"; char* ss[] = {"ash", "che", "ashiq", "chester"}; int length = sizeof(ss)/sizeof(ss[0]); int sizeofarray = sizeof(ss); printf("length: %d\n", length); printf("Size of array: %d\n", sizeofarray); // The size of the [ss] array is 32 for(int i=0; i<length; i++){ printf("%s\n", ss[i]); } return 0; }
Find elsewhere
🌐
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 the array of strings, you can define a pointer to access the string from the array. let see a few example code, ... ** To access the string array, we need to create a pointer to the array and initialize the pointer with the array.
🌐
Codecademy
codecademy.com › learn › learn-c-arrays-and-strings
Learn C: Arrays and Strings | Codecademy
These fundamental data structures allow you to store and manipulate data collections efficiently. This course covers creating, accessing, and modifying arrays, as well as using arrays to handle strings, which are essential for writing functional and optimized programs in C.
Rating: 4.6 ​ - ​ 265 votes
🌐
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.
🌐
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!
🌐
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...
🌐
Big Nerd Ranch
forums.bignerdranch.com › objective-c programming (2nd edition) › 39. c strings
How would I make a array of strings in C? - 39. C Strings - Big Nerd Ranch Book Forums
June 26, 2022 - I’m attempting to make a array of strings in C. If I use this code: char (*a[2])[14]; a[0]="blah"; a[1]="hmm"; gcc gives me “warning: assignment from incompatible pointer type”. What is the right method for doing this…
🌐
OverIQ
overiq.com › c-programming-101 › array-of-strings-in-c › index.html
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…
🌐
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.
🌐
YouTube
m.youtube.com › watch
Arrays of strings in C explained!
Share your videos with friends, family, and the world
Published   April 1, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - This null character marks the end of the string and is essential for proper string manipulation. Unlike many modern languages, C does not have a built-in string data type. Instead, strings are implemented as arrays of char.
🌐
Studytonight
studytonight.com › c › string-and-character-array.php
String and Character Arrays in C Language | Studytonight
September 17, 2024 - Learn how to create a string, character arrays in C, string input and output and string functions in C.