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
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
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
freeing a jagged string array?

Your description is too vague for us to help you.

Could you clarify how your array is allocated?

More on reddit.com
๐ŸŒ r/C_Programming
9
1
December 18, 2017
printing string array seperately in C
Breaking up a string like yours into the substrings (separated by the colon character) is a task often referred to as tokenizing a string (the sub-strings are tokens - e.g. "George" would be the second token). You can use the strtok function from the string library to do this. More on reddit.com
๐ŸŒ r/C_Programming
9
1
February 20, 2021
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ cprogramming โ€บ c array of strings
C Array of Strings
June 10, 2012 - 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.
๐ŸŒ
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:
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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โ€ฆ
Find elsewhere
๐ŸŒ
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...
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ c-strings
Strings in C (With Examples)
Arrays and strings are second-class citizens in C; they do not support the assignment operator once it is declared. For example, char c[100]; c = "C programming"; // Error!
๐ŸŒ
SkillVertex
skillvertex.com โ€บ blog โ€บ array-of-strings-in-c
Array Of Strings In C -
May 10, 2024 - In C, an array of strings is typically represented as a one-dimensional array of strings, where each element of the array is a pointer to a string (which is essentially a one-dimensional array of characters).
๐ŸŒ
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, also referred to as an array of strings in C, is a two-dimensional array that contains strings as elements. These data structures are useful when working with textual data.
๐ŸŒ
PREP INSTA
prepinsta.com โ€บ home โ€บ all about c language โ€บ array v/s string in c
Array v/s String in C
March 18, 2025 - Array is defined as a contiguous block of memory in which similar type of data is stored. Array indexing starts with size 0 and ends with size -1. String is defined as a sequence of character which terminates with a null character.
๐ŸŒ
Scribd
scribd.com โ€บ presentation โ€บ 581212285 โ€บ Ch-3-ARRAY-AND-STRING
Arrays and Strings Guide | PDF | Array Data Structure | String (Computer Science)
It covers topics like one-dimensional and two-dimensional arrays, declaring and initializing arrays, string storage and built-in string functions. It defines arrays as a fixed-size collection of elements of the same data type.
๐ŸŒ
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!
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - A string is an array of characters terminated by a special character '\0' (null character).
๐ŸŒ
Aticleworld
aticleworld.com โ€บ home โ€บ array of strings in c
Array of Strings in C - Aticleworld
February 26, 2023 - Similarly, an array of strings means a collection of several strings. The string is a 1D array of characters terminated with the null character. Since strings are arrays of characters, the array of strings will evolve into a two-dimensional ...
๐ŸŒ
HAPPYDOER DIRECTORY
happydoer.com โ€บ home โ€บ blog โ€บ arrays and strings in c: a practical guide
Arrays and Strings in C: A Practical Guide - HAPPYDOER DIRECTORY - FZCO | Sale Elearning Courses Online
September 4, 2024 - In C programming, arrays and strings are fundamental structures that are used to store and manipulate collections of data. Understanding how to effectively use these structures is crucial for writing efficient and effective C programs.
๐ŸŒ
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 ...
๐ŸŒ
Studytonight
studytonight.com โ€บ c โ€บ string-and-character-array.php
String and Character Arrays in C Language | Studytonight
September 17, 2024 - A string is actually a one-dimensional array of characters in C language. These are often used to create meaningful and readable programs.