How do you create an array of pointers in C?

To create an array of pointers in C, you have one option, you declare:

  type *array[CONST];  /* create CONST number of pointers to type */

With C99+ you can create a Variable Length Array (VLA) of pointers, e.g.

  type *array[var];   /* create var number of pointers to type */

The standard defines both in C11 Standard - 6.7.6.2 Array declarators and discusses subscripting in C11 Standard - 6.5.2.1 Array subscripting.

A short example using an array of pointers, assigning a pointer to each row in a 2D array to an array of pointers to int, e.g.

#include <stdio.h>
#include <stdlib.h>

#define COL 3
#define MAX 5

int main (void) {

    int arr2d[MAX][COL] = {{ 0 }},  /* simple 2D array */
        *arr[MAX] = { NULL },       /* 5 pointers to int */
        i, j, v = 0;

    for (i = 0; i < MAX; i++) {     /* fill 2D array */
        for (j = 0; j < COL; j++)
            arr2d[i][j] = v++;
        arr[i] = arr2d[i];          /* assing row-pointer to arr */
    }

    for (i = 0; i < MAX; i++) {     /* for each pointer */
        for (j = 0; j < COL; j++)   /* output COL ints */
            printf (" %4d", arr[i][j]);
        putchar ('\n');
    }
}

Example Use/Output

$ ./bin/array_ptr2int_vla
    0    1    2
    3    4    5
    6    7    8
    9   10   11
   12   13   14

Another fundamental of C is the pointer-to-pointer, but it is not an "Array", though it is routinely called a "dynamic array" and can be allocated and indexed simulating an array. The distinction between an "Array" and a collection of pointers is that with an Array, all values are guaranteed to be sequential in memory -- there is no such guarantee with a collection of pointers and the memory locations they reference.

So What Does int **arr[CONST] Declare?

In your question you posit a declaration of int** arr[5] = {0xbfjeabfbfe,0x...};, so what does that declare? You are declaring Five of something, but what? You are declaring five pointer-to-pointer-to-int. Can you do that? Sure.

So what do you do with a pointer-to-pointer-to-something? The pointer-to-poitner forms the backbone of dynamically allocated and reallocated collection of types. They are commonly termed "dynamically allocated arrays", but that is somewhat a misnomer, because there is no guarantee that all values will be sequential in memory. You will declare a given number of pointers to each int** in the array. You do not have to allocate an equal number of pointers.

(note: there is no guarantee that the memory pointed to by the pointers will even be sequential, though the pointers themselves will be -- make sure you understand this distinction and what an "Array" guarantees and what pointers don't)

int** arr[5] declares five int**. You are then free to assign any address to you like to each of the five pointers, as long as the type is int**. For example, you will allocate for your pointers with something similar to:

  arr[i] = calloc (ROW, sizeof *arr[i]);  /* allocates ROW number of pointers */

Then you are free to allocate any number of int and assign that address to each pointer, e.g.

  arr[i][j] = calloc (COL, sizeof *arr[i][j]); /* allocates COL ints */

You can then loop over the integers assigning values:

  arr[i][j][k] = v++;

A short example using your int** arr[5] type allocation could be similar to:

#include <stdio.h>
#include <stdlib.h>

#define ROW 3
#define COL ROW
#define MAX 5

int main (void) {

    int **arr[MAX] = { NULL },  /* 5 pointer-to-pointer-to-int */
        i, j, k, v = 0;

    for (i = 0; i < MAX; i++) { /* allocate ROW pointers to each */
        if ((arr[i] = calloc (ROW, sizeof *arr[i])) == NULL) {
            perror ("calloc - pointers");
            return 1;
        }
        for (j = 0; j < ROW; j++) { /* allocate COL ints each pointer */
            if ((arr[i][j] = calloc (COL, sizeof *arr[i][j])) == NULL) {
                perror ("calloc - integers");
                return 1;
            }
            for (k = 0; k < COL; k++)   /* assign values to ints */
                arr[i][j][k] = v++;
        }
    }

    for (i = 0; i < MAX; i++) { /* output each pointer-to-pointer to int */
        printf ("pointer-to-pointer-to-int: %d\n\n", i);
        for (j = 0; j < ROW; j++) {     /* for each allocated pointer */
            for (k = 0; k < COL; k++)   /* output COL ints */
                printf ("  %4d", arr[i][j][k]);
            free (arr[i][j]);   /* free the ints */
            putchar ('\n');
        }
        free (arr[i]);      /* free the pointer */
        putchar ('\n');
    }

    return 0;
}

You have allocated for five simulated 2D arrays assigning the pointer to each to your array of int **arr[5], the output would be:

Example Use/Output

$ ./bin/array_ptr2ptr2int
pointer-to-pointer-to-int: 0

     0     1     2
     3     4     5
     6     7     8

pointer-to-pointer-to-int: 1

     9    10    11
    12    13    14
    15    16    17

pointer-to-pointer-to-int: 2

    18    19    20
    21    22    23
    24    25    26

pointer-to-pointer-to-int: 3

    27    28    29
    30    31    32
    33    34    35

pointer-to-pointer-to-int: 4

    36    37    38
    39    40    41
    42    43    44

Hopefully this has helped with the distinction between an array of pointers, and an array of pointers-to-pointer and shown how to declare and use each. If you have any further questions, don't hesitate to ask.

Answer from David C. Rankin on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί c language β€Ί array-of-pointers-in-c
Array of Pointers in C - GeeksforGeeks
July 23, 2025 - As shown in the above example, each element of the array is a pointer pointing to an integer. We can access the value of these integers by first selecting the array element and then dereferencing it to get the value.
🌐
TutorialsPoint
tutorialspoint.com β€Ί cprogramming β€Ί c_array_of_pointers.htm
Array of Pointers in C
If we store the address of an array ... To create an array of pointers in C language, you need to declare an array of pointers in the same way as a pointer declaration....
Discussions

What are Array of Pointers?
If you have something like const char *argv[] = {"./a.out", "hello", NULL}; You get this in memory: argv β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ptr β”œβ”€β”€β”€β–Ίβ”‚ ./a.out β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ptr β”œβ”€β” β”œβ”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ NULL β”‚ └─►│ hello β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ You can see that the "./a.out" and "hello" are stored in other places in memory, not inside the array. That’s what a pointer isβ€”a value that can point to another location in memory. Or it can be NULL, which does not point to anything. More on reddit.com
🌐 r/C_Programming
32
37
December 17, 2024
How do you create an array of pointers in C? - Stack Overflow
The standard defines both in C11 Standard - 6.7.6.2 Array declarators and discusses subscripting in C11 Standard - 6.5.2.1 Array subscripting. A short example using an array of pointers, assigning a pointer to each row in a 2D array to an array of pointers to int, e.g. More on stackoverflow.com
🌐 stackoverflow.com
An array of pointers vs a pointer to an array
Declarations in C are written to match their usage. So if you write int *array[100], this means array has type such that *array[100] is of type int. (Ignoring, of course, that 100 is an invalid array index!) So to determine the type of array, we can use the operator precedence rules. Array indexing is higher precedence than dereferencing, so *array[100] means that we first get index into an array, and then dereference the object we get out, and that all should result in an int. This means that array is an array of pointers to int. (*array)[100] reverses this. Now, it says if we dereference array, and then index into whatever we get out as an array, we get an int. Thus, it's a pointer to an array of ints. Lots of people try to explain this in terms of the 'right-left rule' or the 'spiral rule' or whatever - I find these just make things harder. It's all operator precedence. More on reddit.com
🌐 r/C_Programming
6
5
February 1, 2021
Are C arrays pointers ?
Is it because arrays are not pointers and increment operator is not defined for arrays ? That is correct. Technically speaking, even in myArray++ the array is converted to a pointer. However, that pointer does not have a location in memory β€” it is not an "lvalue". The increment operator can only be used on mutable lvalues. It's pretty much the same reason 42++ makes no sense. 42 doesn't have a location in memory either. More on reddit.com
🌐 r/C_Programming
30
43
June 5, 2024
🌐
W3Schools
w3schools.com β€Ί c β€Ί c_pointers_arrays.php
C Pointers and Arrays
Use C pointers to access and step through the elements of an array.
🌐
Reddit
reddit.com β€Ί r/c_programming β€Ί what are array of pointers?
r/C_Programming on Reddit: What are Array of Pointers?
December 17, 2024 -

So i am learning command lines arguments and just came cross char *argv[]. What does this actually do, I understand that this makes every element in the array a pointer to char, but i can't get around as to how all of this is happening. How does it treat every other element as another string? How come because essentialy as of my understanding rn, a simple char would treat as a single contiguous block of memory, how come turning this pointer to another pointer of char point to individual elements of string?

Top answer
1 of 14
79
If you have something like const char *argv[] = {"./a.out", "hello", NULL}; You get this in memory: argv β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ptr β”œβ”€β”€β”€β–Ίβ”‚ ./a.out β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ptr β”œβ”€β” β”œβ”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ NULL β”‚ └─►│ hello β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ You can see that the "./a.out" and "hello" are stored in other places in memory, not inside the array. That’s what a pointer isβ€”a value that can point to another location in memory. Or it can be NULL, which does not point to anything.
2 of 14
13
The only thing that’s guaranteeing is contiguous are the double pointers. If you dereference the first element, that is a pointer to a char, and there might be more chars further along if you move down that row with pointer arithmetic. Dereferencing your second element would be a pointer to another char which might make up a string along that row too (if you defined it as such). Those derefenced pointers have no reason to be contiguous in memory. It’s just that the pointers for themselves are. The only contiguity guarantee here from that statement alone is the array of pointers to char *.
🌐
Scaler
scaler.com β€Ί home β€Ί topics β€Ί array of pointers in c
Array of Pointers in C - Scaler Topics
January 2, 2024 - Array name itself acts as a pointer to the first element of the array and also if a pointer variable stores the base address of an array then we can manipulate all the array elements using the pointer variable only. Pointers can be associated with the multidimensional arrays (2-D and 3-D arrays) ...
Top answer
1 of 3
9

How do you create an array of pointers in C?

To create an array of pointers in C, you have one option, you declare:

  type *array[CONST];  /* create CONST number of pointers to type */

With C99+ you can create a Variable Length Array (VLA) of pointers, e.g.

  type *array[var];   /* create var number of pointers to type */

The standard defines both in C11 Standard - 6.7.6.2 Array declarators and discusses subscripting in C11 Standard - 6.5.2.1 Array subscripting.

A short example using an array of pointers, assigning a pointer to each row in a 2D array to an array of pointers to int, e.g.

#include <stdio.h>
#include <stdlib.h>

#define COL 3
#define MAX 5

int main (void) {

    int arr2d[MAX][COL] = {{ 0 }},  /* simple 2D array */
        *arr[MAX] = { NULL },       /* 5 pointers to int */
        i, j, v = 0;

    for (i = 0; i < MAX; i++) {     /* fill 2D array */
        for (j = 0; j < COL; j++)
            arr2d[i][j] = v++;
        arr[i] = arr2d[i];          /* assing row-pointer to arr */
    }

    for (i = 0; i < MAX; i++) {     /* for each pointer */
        for (j = 0; j < COL; j++)   /* output COL ints */
            printf (" %4d", arr[i][j]);
        putchar ('\n');
    }
}

Example Use/Output

$ ./bin/array_ptr2int_vla
    0    1    2
    3    4    5
    6    7    8
    9   10   11
   12   13   14

Another fundamental of C is the pointer-to-pointer, but it is not an "Array", though it is routinely called a "dynamic array" and can be allocated and indexed simulating an array. The distinction between an "Array" and a collection of pointers is that with an Array, all values are guaranteed to be sequential in memory -- there is no such guarantee with a collection of pointers and the memory locations they reference.

So What Does int **arr[CONST] Declare?

In your question you posit a declaration of int** arr[5] = {0xbfjeabfbfe,0x...};, so what does that declare? You are declaring Five of something, but what? You are declaring five pointer-to-pointer-to-int. Can you do that? Sure.

So what do you do with a pointer-to-pointer-to-something? The pointer-to-poitner forms the backbone of dynamically allocated and reallocated collection of types. They are commonly termed "dynamically allocated arrays", but that is somewhat a misnomer, because there is no guarantee that all values will be sequential in memory. You will declare a given number of pointers to each int** in the array. You do not have to allocate an equal number of pointers.

(note: there is no guarantee that the memory pointed to by the pointers will even be sequential, though the pointers themselves will be -- make sure you understand this distinction and what an "Array" guarantees and what pointers don't)

int** arr[5] declares five int**. You are then free to assign any address to you like to each of the five pointers, as long as the type is int**. For example, you will allocate for your pointers with something similar to:

  arr[i] = calloc (ROW, sizeof *arr[i]);  /* allocates ROW number of pointers */

Then you are free to allocate any number of int and assign that address to each pointer, e.g.

  arr[i][j] = calloc (COL, sizeof *arr[i][j]); /* allocates COL ints */

You can then loop over the integers assigning values:

  arr[i][j][k] = v++;

A short example using your int** arr[5] type allocation could be similar to:

#include <stdio.h>
#include <stdlib.h>

#define ROW 3
#define COL ROW
#define MAX 5

int main (void) {

    int **arr[MAX] = { NULL },  /* 5 pointer-to-pointer-to-int */
        i, j, k, v = 0;

    for (i = 0; i < MAX; i++) { /* allocate ROW pointers to each */
        if ((arr[i] = calloc (ROW, sizeof *arr[i])) == NULL) {
            perror ("calloc - pointers");
            return 1;
        }
        for (j = 0; j < ROW; j++) { /* allocate COL ints each pointer */
            if ((arr[i][j] = calloc (COL, sizeof *arr[i][j])) == NULL) {
                perror ("calloc - integers");
                return 1;
            }
            for (k = 0; k < COL; k++)   /* assign values to ints */
                arr[i][j][k] = v++;
        }
    }

    for (i = 0; i < MAX; i++) { /* output each pointer-to-pointer to int */
        printf ("pointer-to-pointer-to-int: %d\n\n", i);
        for (j = 0; j < ROW; j++) {     /* for each allocated pointer */
            for (k = 0; k < COL; k++)   /* output COL ints */
                printf ("  %4d", arr[i][j][k]);
            free (arr[i][j]);   /* free the ints */
            putchar ('\n');
        }
        free (arr[i]);      /* free the pointer */
        putchar ('\n');
    }

    return 0;
}

You have allocated for five simulated 2D arrays assigning the pointer to each to your array of int **arr[5], the output would be:

Example Use/Output

$ ./bin/array_ptr2ptr2int
pointer-to-pointer-to-int: 0

     0     1     2
     3     4     5
     6     7     8

pointer-to-pointer-to-int: 1

     9    10    11
    12    13    14
    15    16    17

pointer-to-pointer-to-int: 2

    18    19    20
    21    22    23
    24    25    26

pointer-to-pointer-to-int: 3

    27    28    29
    30    31    32
    33    34    35

pointer-to-pointer-to-int: 4

    36    37    38
    39    40    41
    42    43    44

Hopefully this has helped with the distinction between an array of pointers, and an array of pointers-to-pointer and shown how to declare and use each. If you have any further questions, don't hesitate to ask.

2 of 3
3

An array of pointers to ints;

int x = 1;
int y = 42;
int z = 12;

int * array[3];

array[0] = &x;
array[1] = &y;
array[2] = &z;

alternate syntax

int * array[] = {&x,&y,&z};

keeping it simple. Work upwards from there

🌐
BYJUS
byjus.com β€Ί gate β€Ί array-of-pointers-in-c
Declaration Of An Array Of Pointers In C
August 1, 2022 - This way, manipulation of the sensor status becomes very easy. The thermo[0] will be holding the 1st sensor’s address. The thermo[1] will be holding the 2nd sensor’s address and so on. Now, since it’s an array, it can interact directly with the thermo pointer indexed in the array.
Find elsewhere
🌐
Medium
medium.com β€Ί @Dev_Frank β€Ί pointer-arrays-08100ef37ede
POINTER & ARRAYS. Understanding C Pointers and Arrays | by Dev Frank | Medium
February 17, 2024 - &pointer gives the address of the pointer variable itself. 3. String Literal Initialization: char array[ ] = β€œabc”` initializes the array with β€˜a’, β€˜b’, β€˜c’, and β€˜\0’. char *pointer = β€œabc”` sets the pointer to the address of the β€œabc” string (often stored in read-only memory).
🌐
Testbook
testbook.com β€Ί home β€Ί gate β€Ί an array of pointers in c - understanding with examples | testbook.com
An Array of Pointers in C - Understanding with Examples | Testbook.com
When we require multiple pointers in a C program, we create an array of multiple pointers and use it in the program. We do the same for all the other data types in the C program. When we want to point at multiple variables or memories of the ...
🌐
OverIQ
overiq.com β€Ί c-programming-101 β€Ί array-of-pointers-in-c
Array of Pointers in C - C Programming Tutorial - OverIQ.com
Just like we can declare an array of int, float or char etc, we can also declare an array of pointers, here is the syntax to do the same. Syntax: d…
🌐
Programiz
programiz.com β€Ί c-programming β€Ί c-pointers-arrays
Relationship Between Arrays and Pointers in C Programming (With Examples)
In this tutorial, you'll learn about the relationship between arrays and pointers in C programming. You will also learn to access array elements using pointers with the help of examples.
🌐
Cornell Computer Science
cs.cornell.edu β€Ί courses β€Ί cs3410 β€Ί 2024fa β€Ί notes β€Ί pointer.html
Arrays & Pointers - CS 3410
You can think of the array having a base address \(b\). Then, the address of an element at index \(i\) has this address: ... In fact, C lets you treat an array itself as if it were a pointer to the first element: i.e., the base address \(b\).
🌐
Wikibooks
en.wikibooks.org β€Ί wiki β€Ί C_Programming β€Ί Pointers_and_arrays
C programming/Pointers and arrays - Wikibooks, open books for an open world
June 9, 2004 - How to reference the value to which ... '*': value = *pointer;) How they relate to arrays (the vast majority of arrays in C are simple lists, also called "1 dimensional arrays", but we will briefly cover multi-dimensional ...
🌐
Study.com
study.com β€Ί computer science courses β€Ί computer science 111: programming in c
Arrays of Pointers in C Programming: Definition & Examples - Lesson | Study.com
September 27, 2021 - Now if we want to access sorted data, it is possible with the array of pointers, and to access the original data, use the array of strings. Sometimes the data may be needed in more than one order. For example, we have the name and score of all six students mentioned in the previous example. We may need the data sorted by name and by scores. In this case, we must either keep two copies of the data, each sorted differently, or use pointers to an individual student and swap pointers.
🌐
Unstop
unstop.com β€Ί home β€Ί blog β€Ί array of pointers in c explained with detailed code examples
Array Of Pointers In C Explained With Detailed Code Examples
February 29, 2024 - An array of pointers in C is a data structure containing pointers to variables of the same data types that are stored in continuous memory locations.
🌐
Log2Base2
log2base2.com β€Ί C β€Ί pointer β€Ί array-of-pointers-in-c.html
Array of pointers in c | Application of array of pointers
Like array of variables, we can also use array of pointers in c.In this tutorial explains array of pointers and its application.
🌐
Medium
safalgautam.medium.com β€Ί c-pointers-and-arrays-complete-foundation-guide-b287778f19eb
C Pointers and Arrays β€” Complete Foundation Guide | by SAFAL GAUTAM | Medium
April 26, 2026 - The key rule: arrays decay into pointers when passed to functions. ... What actually gets passed? Not all 5 elements. Not a copy. Just one address β€” the address of a[0]. That's it.
🌐
O'Reilly
oreilly.com β€Ί library β€Ί view β€Ί understanding-and-using β€Ί 9781449344535 β€Ί ch04.html
4. Pointers and Arrays - Understanding and Using C Pointers [Book]
May 8, 2013 - Quick Review of ArraysOne-Dimensional ArraysTwo-Dimensional ArraysMultidimensional ArraysPointer Notation and ArraysDifferences Between Arrays and PointersUsing malloc to Create a One-Dimensional ArrayUsing the realloc Function to Resize an ArrayPassing a One-Dimensional ArrayUsing Array NotationUsing Pointer NotationUsing a One-Dimensional Array of PointersPointers and Multidimensional ArraysPassing a Multidimensional ArrayDynamically Allocating a Two-Dimensional ArrayAllocating Potentially Noncontiguous MemoryAllocating Contiguous MemoryJagged Arrays and PointersSummary Β· String Fundamental
Author: Richard M Reese
Published: 2013
Pages: 223
🌐
Steve's Data Tips and Tricks
spsanderson.com β€Ί steveondata β€Ί posts β€Ί 2025-03-12
Arrays and Pointers in C: A Complete Guide for Beginners – Steve’s Data Tips and Tricks
March 12, 2025 - If you’re new to C programming, understanding arrays and pointers might seem intimidating at first. However, these concepts are fundamental to mastering C and can make your code more efficient once you understand them. This guide breaks down these concepts in simple language with plenty of examples to help you grasp how arrays and pointers work in C and how they relate to each other.
🌐
LabEx
labex.io β€Ί tutorials β€Ί c-array-of-pointers-123201
Mastering Array of Pointers in C | LabEx
In this lab, we will learn how to access an array of integer pointers and an array of character pointers.