C Array of Pointers

Intermediate
6 min read
Updated: Nov 2026
1 example

What Is Array of Pointers?

An array of pointers holds addresses. The most common case is an array of strings: const char *names[] = {"Ann", "Bob"}. Each element points to a separate string, so rearranging the array only moves pointers, not text. argv in main is an array of pointers.

Remember
const char *names[] = {"Ann", "Bob", "Cy"};
names[1]            /* "Bob" (a pointer)  */
names[1][0]         /* 'B'                */
int *rows[3];       /* three int pointers */

Cheat Sheet

Keep these facts handy while you work with Array of Pointers in C.

TopicDetail
Declaretype *name[count];
ElementEach is a pointer
StringsArray of const char *
Compareint (*p)[3] is a pointer to an array

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Pointer to Pointer.

Example 1 — A table of strings

Print each name and its length.

C
#include <stdio.h>
#include <string.h>

int main(void) {
    const char *names[] = {"Ann", "Bob", "Cy"};
    int n = sizeof names / sizeof names[0];

    for (int i = 0; i < n; i++) {
        printf("%d: %s (%zu)\n", i, names[i], strlen(names[i]));
    }
    return 0;
}

How It Works

  1. names holds three pointers to string literals.
  2. sizeof names / sizeof names[0] counts pointers, not characters.
  3. Each names[i] can be passed to string functions.

Edge Cases & Pitfalls

Check these before relying on Array of Pointers in real programs.

2d

Not a 2D char array

Strings in an array of pointers can have different lengths and may be read-only literals.

prec

Precedence in declarations

int *a[3] is an array of pointers; int (*a)[3] is a pointer to an array.

Key Takeaways

  • Elements: pointers, not values.
  • Strings: a natural fit.
  • Sorting: swap pointers, not text.

One line: An array of pointers holds addresses.

Frequently Asked Questions

A 2D array is one contiguous block of rows with equal length. An array of pointers holds separate addresses whose targets may be scattered and of different lengths.
argv is an array of char pointers holding the command-line arguments. argv[0] is usually the program name.
Continue with "C Pointer to Pointer" next. Use double pointers to change a pointer from inside a function. The C Pointers hub lists every topic in order.

Next: Pointer to Pointer

Use double pointers to change a pointer from inside a function.

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.

9 people found this page helpful