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 - After that, we can assign a string of any length to these pointers. ... Note: Here, each string will take different amount of space so offset will not be the same and does not follow any particular order. This method of storing strings has the advantage of the traditional array of strings. Consider the following two examples: ... // C Program to print Array of strings without array of pointers #include <stdio.h> int main() { char str[3][10] = { "Geek", "Geeks", "Geekfor" }; printf("String array Elements are:\n"); for (int i = 0; i < 3; i++) { printf("%s\n", str[i]); } return 0; }
🌐
TutorialsPoint
tutorialspoint.com β€Ί cprogramming β€Ί c_array_of_pointers.htm
Array of Pointers in C
There may be a situation when we want to maintain an array that can store pointers to an "int" or "char" or any other data type available. Here is the declaration of an array of pointers to an integer βˆ’ ... 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 ... 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. This answer shows how to statically initialize a 2D array. 2018-04-24T23:58:24.503Z+00:00 ... Save this answer. ... Show activity on this post. How do I create an array of ... 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
Confused about pointer pointers and array pointers
dont combine multi dimension arrays and pointers, ull get lost very quick as for ur actual question, someone smarter than me might answer More on reddit.com
🌐 r/C_Programming
11
2
October 20, 2023
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
People also ask

What is the advantage of using an array of pointers in C?
When we want to point at multiple variables or memories of the same data type in a C program, we use an array of pointers. One of the huge advantages of using arrays is that it becomes very easy for a programmer to access all the elements in the program easily. All the elements can be accessed in a single run of a loop in the program.
🌐
testbook.com
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
What is a pointer of pointer in C?
It is basically a type of multiple indirections in a program. The pointer of a pointer is like a chain of pointers. Now, a pointer usually consists of a variable’s address. But on the other hand, when we define the pointer to a pointer, then the first pointer consists of the second pointer’s address. Now, the second pointer points towards the location of the actual value in the program.
🌐
testbook.com
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
🌐
W3Schools
w3schools.com β€Ί c β€Ί c_pointers_arrays.php
C Pointers and Arrays
The memory address of the first element is the same as the name of the array: int myNumbers[4] = {25, 50, 75, 100}; // Get the memory address of the myNumbers array printf("%p\n", myNumbers); // Get the memory address of the first array element ...
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

🌐
Log2Base2
log2base2.com β€Ί C β€Ί pointer β€Ί array-of-pointers-in-c.html
Array of pointers in c | Application of array of pointers
/* * Program : Array of Pointers * Language : C */ #include<stdio.h> #define size 5 int main() { int *arr[size]; int a = 10, b = 20, c = 30, d = 40, e = 50, i; arr[0] = &a; arr[1] = &b; arr[2] = &c; arr[3] = &d; arr[4] = &e; printf("Address of a = %p\n",arr[0]); printf("Address of b = %p\n",arr[1]); printf("Address of c = %p\n",arr[2]); printf("Address of d = %p\n",arr[3]); printf("Address of e = %p\n",arr[4]); for(i = 0; i < size; i++) printf("value stored at arr[%d] = %d\n",i,*arr[i]); return 0; }
🌐
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 - To declare an array of pointers in C, we must specify the data type of the elements, the array name, and the size of the array of pointers. Also, note that we use an asterisk(*) to signify it is an array of pointers. ... 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....
Find elsewhere
🌐
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 - Let's create an integer array A of five elements, with the data values as 1, 2, 3, 4, and 5. The array of five pointers P, will point to array A as shown in this next image:
🌐
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
So, we can access the status of the first sensor using thermo[0], the second sensor using thermo[1], and so on. ... An array of pointers can be declared in a similar way as we declare arrays of other data types like char, float, int, etc.
🌐
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.
🌐
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.
🌐
Microchip Developer Help
developerhelp.microchip.com β€Ί xwiki β€Ί bin β€Ί view β€Ί software-tools β€Ί compilers β€Ί c-programming β€Ί data-pointers β€Ί arrays-of-pointers
C Programming Arrays Of Pointers - Developer Help
August 26, 2025 - To use the value pointed to by a pointer array element, just dereference it like you would an ordinary variable: ... Using *p[0] is the same as using the object it points to, such as x or the string literal "My String" from before. ... 1 int i = 0; 2 char *str[] = {"Zero", "One", "Two", "Three", ...
🌐
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 ... 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....
🌐
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 *.
🌐
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.
🌐
Cornell Computer Science
cs.cornell.edu β€Ί courses β€Ί cs3410 β€Ί 2024fa β€Ί notes β€Ί pointer.html
Arrays & Pointers - CS 3410
When I ran this program on my machine once, it told me that the first element of the array was located at address 0x1555d56b90, the next element was at 0x1555d56b94, and so on, with each address increasing by 4 with each element. Remember that ints are 4 bytes on our platform, so these addresses mean that the elements are packed densely, each one next to the other. 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\). This works, for example:
🌐
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.
🌐
Upgrad
upgrad.com β€Ί home β€Ί tutorials β€Ί software & tech β€Ί array of pointers in c
Array of Pointers in C | Beginner’s Guide
April 30, 2025 - Pointer arithmetic allows you to move through memory addresses in an array. For example, incrementing a pointer in an array of integers moves to the next integer based on the size of the data type.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί c language β€Ί pointer-array-array-pointer
Pointer to an Array | Array Pointer - GeeksforGeeks
#include <stdio.h> int main() { int arr[2][3] = {{1, 2, 3}, {4, 5, 6}}; // pointer to above array int (*ptr)[2][3] = &arr; // Traversing the arry using ptr for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { printf("%d ", (*ptr)[i][j]); ...
Published: April 30, 2025
🌐
Programiz
programiz.com β€Ί c-programming β€Ί c-pointer-examples
C Array and Pointer Examples
Arrays in C Programming Β· Pointers in C Start Learning C Β· Check odd/even number Β· Find roots of a quadratic equation Β· Print Pyramids and Patterns Β· Check prime number Β· Print the Fibonacci series Explore C Examples Β· string.h Β· math.h Β· ctype.h View all Β· Created with over a decade of experience.
🌐
Programiz
programiz.com β€Ί c-programming β€Ί c-pointers-arrays
Relationship Between Arrays and Pointers in C Programming (With Examples)
#include <stdio.h> int main() { ... element ptr = &x[2]; printf("*ptr = %d \n", *ptr); // 3 printf("*(ptr+1) = %d \n", *(ptr+1)); // 4 printf("*(ptr-1) = %d", *(ptr-1)); // 2 return 0; } ... In this example, &x[2], the address of the third element, is assigned to the ptr pointer...