C Array of Strings

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Array of Strings?

Programs often need many strings: menus, names, keywords. Use a 2D char array (char table[R][C]) for fixed-width rows, or an array of pointers (char *rows[]) pointing at literals or separately allocated buffers.

Remember
char days[3][10] = { "Mon", "Tue", "Wed" };
char *hi[] = { "yes", "no", NULL };

Cheat Sheet

TopicDetail
2D arraychar a[R][C]; — each row C bytes
Pointer arraychar *p[R]; — each entry a pointer
IterateLoop rows; print with %s
Mutable rows2D array rows are writable arrays

C Examples

Compile with gcc file.c -std=c11 -Wall -o out. Next: String Functions.

Example 1

C
#include <stdio.h>

int main(void) {
    char colors[3][8] = { "red", "green", "blue" };
    char *labels[] = { "A", "B", "C" };
    int i;

    for (i = 0; i < 3; i++) {
        printf("%s / %s\n", colors[i], labels[i]);
    }
    return 0;
}

How It Works

  1. colors stores three mutable rows of up to 7 chars + \0.
  2. labels holds pointers to string literals.
  3. The loop prints matching pairs by index.

Edge Cases & Pitfalls

width

Row too short

char a[2][3] = {"toolong"}; truncates or fails to fit with \0.

literal

Pointer array to literals

Do not write through labels[i] if it points at a literal.

Key Takeaways

  • Fixed table: use char [R][C].
  • List of literals: use char *[].
  • Heap list: combine with malloc for dynamic lengths.

One line: Store many strings as a 2D char array or an array of char pointers.

Frequently Asked Questions

Start with char name[N][M] for a small fixed table. Add pointer arrays when you share literals or heap strings.
main's argv is an array of char * — each points to a command-line argument string.
Open the string.h Function Index, or continue with Pointers and Arrays.

Next: String Functions

Continue the C strings track.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful