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

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

A true "ARRAY OF STRINGS". Here's how I did it using pointers. :)
My project needed an "Array of Strings" to simplify the code, allowing me to manipulate several strings at once using "for" loops, instead of having to type a separate line for each string I want to read, write, or edit. … More on forum.arduino.cc
🌐 forum.arduino.cc
19
3
June 22, 2015
Array type annotation syntax: String[] -vs- [String]
I prefer Array[String]. [] should not just be array syntax, but generics in general. There's no reason to give array a special treatment. You should be able to replace Array with List or something else and not have to change any other part of the syntax. In Haskell [ ] is a list, and lists are given special treatment. They're linked lists and often not what you want anyway. All of Haskell's standard prelude gives lists a special treatment which is part of why there have been attempts to replace it with a better prelude. For example, functions like map are specific to lists, which is why the generic version, Functor, has to name it's map fmap because map is already taken. But since lists are functors, you can replace any instance of map with fmap and nothing will change. Obvious here that map would be better in the functor to begin with, and lists don't deserve the special treatment. Lists should instead be written the same as any other type in Haskell, for consistency. data List a = Nil | Cons a (List a) class Functor f where map :: f a -> (a -> b) -> f b instance Functor List where map :: List a -> (a -> b) -> List b = ... Pretty sure most Haskellers would agree. The reason it's this way is because Haskell's lists pre-date the introduction of typeclasses to the language. More on reddit.com
🌐 r/ProgrammingLanguages
57
45
July 13, 2022
[C++] What's the difference between an array and a string?
They are definitely related, but they are different things. A string is an ordered sequence of characters (exactly what a "character" is is more complex than you might imagine) of finite length. In any civilized language there will be various operations you can perform on strings like getting a particular character, comparing two strings, getting a substring, etc., but those aren't part of the definition of "string", those are just helpful things that string libraries let you do. A string is usually implemented as an array under the hood. An array is a data structure that consists of a collection of elements that can be accessed by an "index". It's probably the case that the elements of the array appear sequentially in memory and the index is an integer, but you could also view this as a specialization of the more general data structure "associative array". Either way, the elements can be of any type (although usually, but not always, all the elements have to be the same type). It's not correct to say that a string is an array of characters, but in some languages it's very close. It's probably true to say that a string in your favorite programming language is implemented as an array of characters. More on reddit.com
🌐 r/learnprogramming
20
13
March 12, 2021
Just an example of string sorting because I couldn't find any other.
For Unicode no explicit support beyond the implicit utf8 stuff is in there. See https://zig.news/dude_the_builder/unicode-string-operations-536e for a discussion. More on reddit.com
🌐 r/Zig
7
13
November 20, 2023
People also ask

Can I modify strings in an array of strings in C?
Yes, if you're using a 2D char array. But if you’re using string literals with pointers (char *arr[]), modifying them is unsafe.
🌐
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)
How do I print all strings in an array?
Loop through with a for loop and use printf("%s", arr[i]); to print each string.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › array-of-strings
Array of Strings in C Language (With Examples)
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_array_of_strings.htm
Array of Strings in C
When strings are stored in array, there are a lot use cases. Let study some of the use cases. In the following example, we store the length of first string and its position (which is "0") in the variables "l" and "p" respectively.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › array-of-strings-in-cpp-5-different-ways-to-create
Array of Strings in C++ - GeeksforGeeks
October 3, 2025 - This issue is discussed in this article - Array of Strings in C · But as C++ strings are dynamic, there is no space wastage issue as each string only occupies the requires space and these can be updated anytime without worrying about the allocated size. For example, we can modify and update the elements of the array arr simply by using the assignment operator:
🌐
W3Schools
w3schools.com › java › java_arrays.asp
Java Arrays
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; ... You can access an array element by referring to the index number. This statement accesses the value of the first element in cars:
🌐
Arduino Forum
forum.arduino.cc › projects › programming
A true "ARRAY OF STRINGS". Here's how I did it using pointers. :) - Programming - Arduino Forum
June 22, 2015 - But when I googled for info on ... arrays being loaded with constants, such as: char* myStrings[]={"This is string 1", "This is string 2", "This is string 3", "This is......
Find elsewhere
🌐
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.
🌐
Whitman College
whitman.edu › mathematics › java_tutorial › java › nutsandbolts › arraysAndStrings.html
Arrays and Strings
Notice the use of arrayOfInts.length to retrieve the current length of the array. length is a property provided for all Java arrays. Arrays can contain any legal Java data type including reference types such as objects or other arrays. For example, the following declares an array that can contain ten String objects.
🌐
WsCube Tech
wscubetech.com › resources › c-programming › array-of-strings
Array of Strings in C Language (With Examples)
July 27, 2026 - Learn how to create and use an array of strings in C programming tutorial. Explore different methods and operations with examples, output, and explanations.
🌐
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 this example, we have initialized a two-dimensional character array car with a maximum of 5 strings of size 20.
🌐
GeeksforGeeks
geeksforgeeks.org › c# › c-sharp-arrays-of-strings
C# | Arrays of Strings - GeeksforGeeks
July 11, 2025 - // declaration using string keyword string[] s1; // declaration using String class object // by giving its size 4 String[] s2 = new String[4]; Initialization of Arrays of Strings: Arrays can be initialized after the declaration. It is not necessary to declare and initialize at the same time using the new keyword. However, Initializing an Array after the declaration, it must be initialized with the new keyword. It can’t be initialized by only assigning values. Example:
🌐
W3Schools
w3schools.com › home › c tutorial › c arrays of strings
C Arrays of Strings
Each row is one string. The \0 shows where the string ends, and the rest of the row is not used. Use a for loop to print all the strings in the array:
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-string-array
Java String Array: Declaration, Initialization & Examples | DigitalOcean
August 3, 2022 - Master Java String arrays with declaration, initialization, and manipulation examples. Learn iteration, sorting, searching, and conversion techniques.
🌐
Aticleworld
aticleworld.com › home › array of strings in c
Array of Strings in C - Aticleworld
February 26, 2023 - This array could store a maximum of 5 strings and the max length of strings would be 10. In the above example, I have initialized my 2d array with some names that as “PoojaS1”, “PoojaS2”,.. etc.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › c programming tutorial › strings array in c
Strings Array in C | What is an array of string? | Functions of strings
March 18, 2023 - A String can be defined as a one-dimensional array of characters, so an array of strings is two –dimensional array of characters. ... From the given syntax there are two subscripts first one is for how many strings to declare and the second is to define the maximum length of characters that each string can store including the null character. C concept already explains that each character takes 1 byte of data while allocating memory, the above example of syntax occupies 2 * 6 =12 bytes of memory.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
W3Schools
w3schools.com › cs › cs_arrays.php
C# Arrays
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; ... You access an array element by referring to the index number. This statement accesses the value of the first element in cars:
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
Create String Arrays - MATLAB & Simulink
Create a string array containing multiple strings using the [] operator. str is a 2-by-3 string array that contains six strings. str = ["Mercury","Gemini","Apollo"; "Skylab","Skylab B","ISS"] str = 2×3 string "Mercury" "Gemini" "Apollo" "Skylab" "Skylab B" "ISS" Find the length of each string ...
🌐
TutorialsPoint
tutorialspoint.com › article › cplusplus-array-of-strings
C++ Array of Strings
July 21, 2025 - We initialized the first five elements with string literals. We then accessed and printed the first and fourth elements of the array using cout. Here is a simple example that demonstrates how to declare, initialize, and access an array of strings in C++.
🌐
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 - The array of strings can contain strings given by number_of_strings of length given by maximum_length. Let's look at a C code example that uses this method to declare an array of strings.
🌐
Unstop
unstop.com › home › blog › string array in java | create, operations & more (+examples)
String Array In Java | Create, Operations & More (+Examples)
January 15, 2025 - This allows for efficient access and manipulation of elements, especially when you know the number of strings beforehand. Example: If you have a string array of days, you can directly access days[2] to get "Wednesday".