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 - Not only we can define the array of pointers for basic data types like int, char, float, etc. but we can also define them for derived and user-defined data types such as arrays, structures, etc. Let's consider the below example where we create an array of pointers pointing to a function for performing the different operations.
🌐
TutorialsPoint
tutorialspoint.com β€Ί cprogramming β€Ί c_array_of_pointers.htm
Array of Pointers in C
It declares ptr as an array of MAX integer pointers. Thus, each element in ptr holds a pointer to an int value. The following example uses three integers, which are stored in an array of pointers, as follows βˆ’
Discussions

How do you create an array of pointers in C? - Stack Overflow
So basically (void*) (array) void is pointer to anything and *array is array of pointers? 2018-04-24T23:38:17.207Z+00:00 ... This doesn't match what is being asked. The question gives a 3D array as an example (int** arr[5]) and asks how to dynamically allocate it. More on stackoverflow.com
🌐 stackoverflow.com
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
Pointers and arrays
int a; This is a scalar. If you read it, you'll get its value. int *ptr; This is a pointer. If you read it, you'll get an address to some int. int a; int *ptr; a = 4; ptr = &a; If you were trying this: ptr = a;, you would get an error. Because assigning the int 4 into a pointer would not work. In the example above, we are instead assigning the address of a. This is what the operator & does. I like to read it as the address of. ########### Now for your question. Let's declare an array of 8 ints, a pointer to an int (uninitialised), and just a regular int. int ar[8]; int *ptr; int a=4; As you probably know, you can assign one of the elements in the array like this: ar[0] = a; You can also adding an int using an element from the array: a = are[2]; This works just fine, because both a and ar[X] are just an int in this context. However, if you try to access ar directly without any brackets, this is different. Although the compiler knows it's an array, because you declared it as such, in this context (without the brackets) the compiler will convert it into a pointer to the first element. Of course, you cannot assign a new address to it like it was a regular pointer, but if you are reading from it, you are getting the address to the first element: ptr = ar; And guess what, since you've just assigned the address of an array into a pointer, you can now totally do this: a = ptr[3]; More on reddit.com
🌐 r/cpp_questions
28
11
November 7, 2021
An array of pointers to arrays of structs
Something I noticed about your code. If you only plan to have values from 0 to 255 inside the pixel structure, you could use the type unsigned char instead, which would reduce the amount of memory used by about 75%. unsigned char has a range from 0 to 255, while unsigned int has a range from 0 to about 4 billion. More on reddit.com
🌐 r/C_Programming
16
7
July 5, 2022
🌐
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.
🌐
Lenovo
lenovo.com β€Ί home
Array of Pointers Explained: The Ultimate Guide | Lenovo US
Yes, you can initialize an array of pointers at the time of declaration. For example, you could write int *arr[] = {&x, &y, &z}; where x, y, z are integers already declared in your code.
🌐
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 - The asterisk (*) is used to specify that it is an array of pointers. ... In this example, we have declared an array of pointers with the size 5.
🌐
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
An array of pointers in C is used when we need to point to multiple variables or memory locations of the same data type. For example, let's say we have five employees working in a bakery. We can store the names of these employees in an array.
Find elsewhere
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.
🌐
Computer Hope
computerhope.com β€Ί jargon β€Ί a β€Ί array-of-pointers.htm
What Is an Array of Pointers?
#include <stdio.h> const int ARRAY_SIZE = 5; int main () { /* first, declare and set an array of five integers: */ int array_of_integers[] = {5, 10, 20, 40, 80}; /* next, declare an array of five pointers-to-integers: */ int i, *array_of_po...
🌐
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 - This code will create an integer variable x and an integer pointer p. Pointer p points to the variable x by storing the address of x. As p is the pointer to x, we can access the x using p. ... When there's a need to point multiple memories of ...
🌐
Hero Vired
herovired.com β€Ί learning-hub β€Ί topics β€Ί array-of-pointers-in-c
Array of Pointers in C with Example Program
In C, we can declare an array of pointers by specifying the base type of the pointers followed by square brackets, which contain the array's size. For example, β€œint *array[5];” declares an array of 5-pointers to integers.
🌐
Javatpoint
javatpoint.com β€Ί cpp-array-of-pointers
C++ Array of Pointers - javatpoint
C++ Array of Pointers with C++ tutorial for beginners and professionals, if-else, switch, break, continue, comments, arrays, object and class, exception, static, structs, inheritance, aggregation etc.
🌐
Scaler
scaler.com β€Ί home β€Ί topics β€Ί array of pointers in c
Array of Pointers in C - Scaler Topics
January 2, 2024 - While arrays of pointers to characters are commonly used for strings, the concept of arrays of pointers isn't restricted to characters alone. You can have an array of pointers to various data types, including int, float, structures, etc. In this example, we utilize an array of void pointers, allowing it to store the address of any data type.
🌐
Sanfoundry
sanfoundry.com β€Ί c-tutorials-array-of-pointers
Array of Pointers in C with Examples
December 31, 2025 - Static Initialization: You can initialize an array of pointers at the time of declaration. int a = 10, b = 20, c = 30; int *arr[3] = {&a, &b, &c}; In this example, each element of arr holds the address of an integer variable.
🌐
OverIQ
overiq.com β€Ί c-programming-101 β€Ί array-of-pointers-in-c
Array of Pointers in C - C Programming Tutorial - OverIQ.com
Here arrop is an array of 5 integer pointers. It means that this array can hold the address of 5 integer variables.
🌐
Tutorialspoint
tutorialspoint.com β€Ί cplusplus β€Ί cpp_array_of_pointers.htm
C++ Array of Pointers
This declares ptr as an array of MAX integer pointers. Thus, each element in ptr, now holds a pointer to an int value. Following example makes use of three integers which will be stored in an array of pointers as follows βˆ’
🌐
Programiz
programiz.com β€Ί c-programming β€Ί c-pointer-examples
C Array and Pointer Examples
In this article, you'll find a list of C programs related to arrays and pointers.