//defines an array of 280 pointers (1120 or 2240 bytes)
int  *pointer1 [280];

//defines a pointer (4 or 8 bytes depending on 32/64 bits platform)
int (*pointer2)[280];      //pointer to an array of 280 integers
int (*pointer3)[100][280]; //pointer to an 2D array of 100*280 integers

Using pointer2 or pointer3 produce the same binary except manipulations as ++pointer2 as pointed out by WhozCraig.

I recommend using typedef (producing same binary code as above pointer3)

typedef int myType[100][280];
myType *pointer3;

Note: Since C++11, you can also use keyword using instead of typedef

using myType = int[100][280];
myType *pointer3;

in your example:

myType *pointer;                // pointer creation
pointer = &tab1;                // assignation
(*pointer)[5][12] = 517;        // set (write)
int myint = (*pointer)[5][12];  // get (read)

Note: If the array tab1 is used within a function body => this array will be placed within the call stack memory. But the stack size is limited. Using arrays bigger than the free memory stack produces a stack overflow crash.

The full snippet is online-compilable at gcc.godbolt.org

int main()
{
    //defines an array of 280 pointers (1120 or 2240 bytes)
    int  *pointer1 [280];
    static_assert( sizeof(pointer1) == 2240, "" );

    //defines a pointer (4 or 8 bytes depending on 32/64 bits platform)
    int (*pointer2)[280];      //pointer to an array of 280 integers
    int (*pointer3)[100][280]; //pointer to an 2D array of 100*280 integers  
    static_assert( sizeof(pointer2) == 8, "" );
    static_assert( sizeof(pointer3) == 8, "" );

    // Use 'typedef' (or 'using' if you use a modern C++ compiler)
    typedef int myType[100][280];
    //using myType = int[100][280];
    
    int tab1[100][280];
    
    myType *pointer;                // pointer creation
    pointer = &tab1;                // assignation
    (*pointer)[5][12] = 517;        // set (write)
    int myint = (*pointer)[5][12];  // get (read)
  
    return myint;
}
Answer from oHo on Stack Overflow
Top answer
1 of 4
47
//defines an array of 280 pointers (1120 or 2240 bytes)
int  *pointer1 [280];

//defines a pointer (4 or 8 bytes depending on 32/64 bits platform)
int (*pointer2)[280];      //pointer to an array of 280 integers
int (*pointer3)[100][280]; //pointer to an 2D array of 100*280 integers

Using pointer2 or pointer3 produce the same binary except manipulations as ++pointer2 as pointed out by WhozCraig.

I recommend using typedef (producing same binary code as above pointer3)

typedef int myType[100][280];
myType *pointer3;

Note: Since C++11, you can also use keyword using instead of typedef

using myType = int[100][280];
myType *pointer3;

in your example:

myType *pointer;                // pointer creation
pointer = &tab1;                // assignation
(*pointer)[5][12] = 517;        // set (write)
int myint = (*pointer)[5][12];  // get (read)

Note: If the array tab1 is used within a function body => this array will be placed within the call stack memory. But the stack size is limited. Using arrays bigger than the free memory stack produces a stack overflow crash.

The full snippet is online-compilable at gcc.godbolt.org

int main()
{
    //defines an array of 280 pointers (1120 or 2240 bytes)
    int  *pointer1 [280];
    static_assert( sizeof(pointer1) == 2240, "" );

    //defines a pointer (4 or 8 bytes depending on 32/64 bits platform)
    int (*pointer2)[280];      //pointer to an array of 280 integers
    int (*pointer3)[100][280]; //pointer to an 2D array of 100*280 integers  
    static_assert( sizeof(pointer2) == 8, "" );
    static_assert( sizeof(pointer3) == 8, "" );

    // Use 'typedef' (or 'using' if you use a modern C++ compiler)
    typedef int myType[100][280];
    //using myType = int[100][280];
    
    int tab1[100][280];
    
    myType *pointer;                // pointer creation
    pointer = &tab1;                // assignation
    (*pointer)[5][12] = 517;        // set (write)
    int myint = (*pointer)[5][12];  // get (read)
  
    return myint;
}
2 of 4
13

Both your examples are equivalent. However, the first one is less obvious and more "hacky", while the second one clearly states your intention.

int (*pointer)[280];
pointer = tab1;

pointer points to an 1D array of 280 integers. In your assignment, you actually assign the first row of tab1. This works since you can implicitly cast arrays to pointers (to the first element).

When you are using pointer[5][12], C treats pointer as an array of arrays (pointer[5] is of type int[280]), so there is another implicit cast here (at least semantically).

In your second example, you explicitly create a pointer to a 2D array:

int (*pointer)[100][280];
pointer = &tab1;

The semantics are clearer here: *pointer is a 2D array, so you need to access it using (*pointer)[i][j].

Both solutions use the same amount of memory (1 pointer) and will most likely run equally fast. Under the hood, both pointers will even point to the same memory location (the first element of the tab1 array), and it is possible that your compiler will even generate the same code.

The first solution is "more advanced" since one needs quite a deep understanding on how arrays and pointers work in C to understand what is going on. The second one is more explicit.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ pointer-array-array-pointer
Pointer to an Array | Array Pointer - GeeksforGeeks
The concept of pointer to an array can be extended to multidimensional arrays too: ... To define a pointer to a 2D array, both the number of rows and columns of the array must be specified in the pointer declaration.
Published ย  April 30, 2025
๐ŸŒ
Codedamn
codedamn.com โ€บ news โ€บ c programming
How to use pointers with 2D arrays in C?
March 10, 2024 - In the realm of C programming, understanding the intricacies of pointers and 2D arrays is crucial for developing efficient and robust applications. Pointers, serving as a direct means of accessing memory locations, together with 2D arrays, which are essential for storing matrix-like data, form a ...
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ difference between pointer to pointer and 2d array
r/C_Programming on Reddit: Difference between pointer to pointer and 2d array
August 12, 2023 -

I know that I can go from one of the types 'char [1]' and 'char *' to the other. However, it seems not as easy with 'char [1][1]' and 'char **'.

In my main function I have

`char a[1][1];`

`a[0][0] = 'q';`

`printf("a: %p\n", a);`

`printf("*a: %p\n", *a);`

`printf("**a: %p\n", **a);`

I'm of course compiling with warnings and I know that gcc complains about the 5'th line as **a is actually of type char and not a pointer type. However running the code shows that 'a' and '*a' are actually the same pointer but '**a' is as expected something else (0x71 which I assume is related to 'q' in some way).

I'm trying to make sense of this and it seems that because *a and a are equal **a must also be equal to a because **a=*(*a)=*(a)=*a=a. It seems that the only error in this reasoning can be the types of a, *a, **a.

How is 'a' actually stored in memory? If 'a' is a pointer to another memory location (in my case 0x7fff9841f250) then surely *a should be the value at that memory address which in my case is also 0x7fff9841f250. So then **a would be the value at 0x7fff9841f250 which is the same value as 'a'... It seems that I cannot view the 2d array 'char a[1][1]' as pointers in a way that makes sense. But then how can I think of this type? What is the type and what does a, *a, **a, a[0], a[0][0] actually mean?

Can anyone help me make sense of this?

๐ŸŒ
Log2Base2
log2base2.com โ€บ C โ€บ pointer โ€บ 2d-array-and-pointers-in-c.html
2d array and pointers in c
&arr is a pointer to the entire 2D(3x3) array. i.e. (int*)[3][3] If we move &arr by 1 position(&arr+1), it will point to the next 2D block(3X3). In our case, the base address of the 2D array is 1000.
๐ŸŒ
Dyclassroom
dyclassroom.com โ€บ c โ€บ c-pointers-and-two-dimensional-array
C - Pointers and Two Dimensional Array - C Programming - dyclassroom | Have fun learning :-)
We will assign the address of the first element of the array num to the pointer ptr using the address of & operator. ... The two dimensional array num will be saved as a continuous block in the memory.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ how-to-declare-a-two-dimensional-array-of-pointers-in-c
How to declare a Two Dimensional Array of pointers in C? - GeeksforGeeks
June 29, 2022 - Below is the implementation of the 2D array of pointers. ... #include <stdio.h> // Drivers code int main() { int arr1[5][5] = { { 0, 1, 2, 3, 4 }, { 2, 3, 4, 5, 6 }, { 4, 5, 6, 7, 8 }, { 5, 4, 3, 2, 6 }, { 2, 5, 4, 3, 1 } }; int* arr2[5][5]; // Initialising each element of the // pointer array with the address of // element present in the other array for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { arr2[i][j] = &arr1[i][j]; } } // Printing the array using // the array of pointers printf("The values are\n"); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { printf("%d ", *arr2[i][j]); } printf("\n"); } return 0; }
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 177473-passing-pointer-2d-array-function.html
passing a pointer to a 2d array to a function
Hello cooper1200 Well first of all in order to pass a 2d array you must define in main 2 pointers (int** temp_array , you must also assign to variables (for example i and j) the size of rows and columns.
Find elsewhere
๐ŸŒ
OverIQ
overiq.com โ€บ c-programming-101 โ€บ pointers-and-2-d-arrays
Pointers and 2-D arrays - C Programming Tutorial - OverIQ.com
The important thing to notice is although parr and *parr points to the same address, but parr's base type is a pointer to an array of 5 integers, while *parr base type is a pointer to int. This is an important concept and will be used to access the elements of a 2-D array.
๐ŸŒ
Carnegie Mellon University
cs.cmu.edu โ€บ ~ab โ€บ 15-123S09 โ€บ lectures โ€บ Lecture 06 - Pointer to a pointer.pdf pdf
Lecture 06 2D Arrays & pointer to a ...
2-D arrays are represented as a ยท contiguous block of n blocks each with size m (i.e. can ยท hold m integers(or any data type) in each block). The ... A[1], A[2] etc.. We can access array elements using [ ] operator as A[i] or ยท using pointer operator *(A+i).
Top answer
1 of 10
162

Here you wanna make a pointer to the first element of the array

uint8_t (*matrix_ptr)[20] = l_matrix;

With typedef, this looks cleaner

typedef uint8_t array_of_20_uint8_t[20];
array_of_20_uint8_t *matrix_ptr = l_matrix;

Then you can enjoy life again :)

matrix_ptr[0][1] = ...;

Beware of the pointer/array world in C, much confusion is around this.


Edit

Reviewing some of the other answers here, because the comment fields are too short to do there. Multiple alternatives were proposed, but it wasn't shown how they behave. Here is how they do

uint8_t (*matrix_ptr)[][20] = l_matrix;

If you fix the error and add the address-of operator & like in the following snippet

uint8_t (*matrix_ptr)[][20] = &l_matrix;

Then that one creates a pointer to an incomplete array type of elements of type array of 20 uint8_t. Because the pointer is to an array of arrays, you have to access it with

(*matrix_ptr)[0][1] = ...;

And because it's a pointer to an incomplete array, you cannot do as a shortcut

matrix_ptr[0][0][1] = ...;

Because indexing requires the element type's size to be known (indexing implies an addition of an integer to the pointer, so it won't work with incomplete types). Note that this only works in C, because T[] and T[N] are compatible types. C++ does not have a concept of compatible types, and so it will reject that code, because T[] and T[10] are different types.


The following alternative doesn't work at all, because the element type of the array, when you view it as a one-dimensional array, is not uint8_t, but uint8_t[20]

uint8_t *matrix_ptr = l_matrix; // fail

The following is a good alternative

uint8_t (*matrix_ptr)[10][20] = &l_matrix;

You access it with

(*matrix_ptr)[0][1] = ...;
matrix_ptr[0][0][1] = ...; // also possible now

It has the benefit that it preserves the outer dimension's size. So you can apply sizeof on it

sizeof (*matrix_ptr) == sizeof(uint8_t) * 10 * 20

There is one other answer that makes use of the fact that items in an array are contiguously stored

uint8_t *matrix_ptr = l_matrix[0];

Now, that formally only allows you to access the elements of the first element of the two dimensional array. That is, the following condition hold

matrix_ptr[0] = ...; // valid
matrix_ptr[19] = ...; // valid

matrix_ptr[20] = ...; // undefined behavior
matrix_ptr[10*20-1] = ...; // undefined behavior

You will notice it probably works up to 10*20-1, but if you throw on alias analysis and other aggressive optimizations, some compiler could make an assumption that may break that code. Having said that, i've never encountered a compiler that fails on it (but then again, i've not used that technique in real code), and even the C FAQ has that technique contained (with a warning about its UB'ness), and if you cannot change the array type, this is a last option to save you :)

2 of 10
46

To fully understand this, you must grasp the following concepts:

Arrays are not pointers!

First of all (And it's been preached enough), arrays are not pointers. Instead, in most uses, they 'decay' to the address to their first element, which can be assigned to a pointer:

int a[] = {1, 2, 3};

int *p = a; // p now points to a[0]

I assume it works this way so that the array's contents can be accessed without copying all of them. That's just a behavior of array types and is not meant to imply that they are same thing.



Multidimensional arrays

Multidimensional arrays are just a way to 'partition' memory in a way that the compiler/machine can understand and operate on.

For instance, int a[4][3][5] = an array containing 435 (60) 'chunks' of integer-sized memory.

The advantage over using int a[4][3][5] vs plain int b[60] is that they're now 'partitioned' (Easier to work with their 'chunks', if needed), and the program can now perform bound checking.

In fact, int a[4][3][5] is stored exactly like int b[60] in memory - The only difference is that the compiler now manages it as if they're separate entities of certain sizes (Specifically, four groups of three groups of five).

{
  {1, 2, 3, 4, 5}
  {6, 7, 8, 9, 10}
  {11, 12, 13, 14, 15}
}
{
  {16, 17, 18, 19, 20}
  {21, 22, 23, 24, 25}
  {26, 27, 28, 29, 30}
}
{
  {31, 32, 33, 34, 35}
  {36, 37, 38, 39, 40}
  {41, 42, 43, 44, 45}
}
{
  {46, 47, 48, 49, 50}
  {51, 52, 53, 54, 55}
  {56, 57, 58, 59, 60}
}

From this, you can clearly see that each "partition" is just an array that the program keeps track of.



Syntax

Now, arrays are syntactically different from pointers. Specifically, this means the compiler/machine will treat them differently. This may seem like a no brainer, but take a look at this:

int a[3][3];

printf("%p %p", a, a[0]);

The above example prints the same memory address twice, like this:

0x7eb5a3b4 0x7eb5a3b4

However, only one can be assigned to a pointer so directly:

int *p1 = a[0]; // RIGHT !

int *p2 = a; // WRONG !

Why can't a be assigned to a pointer but a[0] can?

This, simply, is a consequence of multidimensional arrays, and I'll explain why:

At the level of 'a', we still see that we have another 'dimension' to look forward to. At the level of 'a[0]', however, we're already in the top dimension, so as far as the program is concerned we're just looking at a normal array.

You may be asking:

Why does it matter if the array is multidimensional in regards to making a pointer for it?

It's best to think this way:

A 'decay' from a multidimensional array is not just an address, but an address with partition data (AKA it still understands that its underlying data is made of other arrays), which consists of boundaries set by the array beyond the first dimension.

This 'partition' logic cannot exist within a pointer unless we specify it:

int a[4][5][95][8];

int (*p)[5][95][8];

p = a; // p = *a[0] // p = a+0

Otherwise, the meaning of the array's sorting properties are lost.

Also note the use of parenthesis around *p: int (*p)[5][95][8] - That's to specify that we're making a pointer with these bounds, not an array of pointers with these bounds: int *p[5][95][8]



Conclusion

Let's review:

  • Arrays decay to addresses if they have no other purpose in the used context
  • Multidimensional arrays are just arrays of arrays - Hence, the 'decayed' address will carry the burden of "I have sub dimensions"
  • Dimension data cannot exist in a pointer unless you give it to it.

In brief: multidimensional arrays decay to addresses that carry the ability to understand their contents.

๐ŸŒ
Aticleworld
aticleworld.com โ€บ home โ€บ how to access two dimensional array using pointers in c
How to access two dimensional array using pointers in C - Aticleworld
May 16, 2020 - After the creation of a new type for the 2d array, create a pointer to the 2d array and assign the address of the 2d array to the pointer.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ explain-pointers-and-two-dimensional-array-in-c-language
Explain pointers and two-dimensional array in C language
Following is the C program for pointers and two-dimensional array โˆ’ ยท #include<stdio.h> main ( ){ int a[3] [3], i,j; int *p; clrscr ( ); printf ("Enter elements of 2D array"); for (i=0; i<3; i++){ for (j=0; j<3; j++){ scanf ("%d", &a[i] [j]); } } p = &a[0] [0]; printf ("elements of 2d array are"); for (i=0; i<3; i++){ for (j=0; j<3; j++){ printf ("%d \t", *(p+i*3+j)); } printf (" "); } getch ( ); }
Top answer
1 of 6
43

char ** doesn't represent a 2D array - it would be an array of pointers to pointers. You need to change the definition of printarray if you want to pass it a 2D array:

void printarray( char (*array)[50], int SIZE )

or equivalently:

void printarray( char array[][50], int SIZE )
2 of 6
12

In main(), the variable "array" is declared as

char array[50][50];

This is a 2500 byte piece of data. When main()'s "array" is passed about, it is a pointer to the beginning of that data. It is a pointer to a char expected to be organized in rows of 50.

Yet in function printarray(), you declare

 char **array

"array" here is a pointer to a char *pointer.

@Lucus suggestion of void printarray( char array[][50], int SIZE ) works, except that it is not generic in that your SIZE parameter must be 50.

Idea: defeat (yeech) the type of parameter array in printarray()

void printarray(void *array, int SIZE ){
    int i;
    int j;
    char *charArray = (char *) array;

    for( j = 0; j < SIZE; j++ ){
        for( i = 0; i < SIZE; i ++){
            printf( "%c ", charArray[j*SIZE + i] );
        }
        printf( "\n" );
    }
}

A more elegant solution is to make the "array" in main() an array of pointers.

// Your original printarray()
void printarray(char **array, int SIZE ){
    int i;
    int j;
    for( j = 0; j < SIZE; j++ ){
        for( i = 0; i < SIZE; i ++){
            printf( "%c ", array[j][i] );
        }
        printf( "\n" );
    }
}

// main()
char **array;
int SIZE;
// Initialization of SIZE is not shown, but let's assume SIZE = 50;
// Allocate table
array = (char **) malloc(SIZE * sizeof(char*));
  // Note: cleaner alternative syntax
  // array = malloc(sizeof *array * SIZE);
// Allocate rows
for (int row = 0; row<SIZE; row++) {
  // Note: sizeof(char) is 1. (@Carl Norum)
  // Shown here to help show difference between this malloc() and the above one.
  array[row] = (char *) malloc(SIZE * sizeof(char));
    // Note: cleaner alternative syntax
    // array[row] = malloc(sizeof(**array) * SIZE);
  }
// Initialize each element.
for (int row = 0; row<SIZE; row++) {
  for (int col = 0; col<SIZE; col++) {
    array[row][col] = 'a';  // or whatever value you want
  }
}
// Print it
printarray(array, SIZE);
...
๐ŸŒ
Medium
medium.com โ€บ @codewithcoders96 โ€บ pointers-and-multidimensional-arrays-in-c-c-137dede5b556
Pointers and Multidimensional Arrays in C/C++ | by Codewithcoders | Medium
August 21, 2024 - Pointers provide powerful capabilities for direct memory access, dynamic memory management, and the creation of complex data structures like linked lists and trees. int a = 10; int *ptr = &a; // 'ptr' now holds the address of 'a' An array is a collection of elements of the same data type stored in contiguous memory locations. Arrays in C/C++ can be single-dimensional (1D) or multidimensional (2D, 3D, etc.).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ pass-2d-array-parameter-c
How to pass a 2D array as a parameter in C? - GeeksforGeeks
So, we can directly specify the parameter of the function as pointer to an array of give size (column size). ... #include <stdio.h> // Funtion that takes 2d array as parameter void print(int (*arr)[3], int n, int m) { for (int i = 0; i < n; ...
Published ย  October 3, 2025
๐ŸŒ
Quora
quora.com โ€บ How-we-can-declare-a-pointer-to-a-2D-array-in-the-C-language
How we can declare a pointer to a 2D array in the C language? - Quora
Just address the pointer to a static/dynamic memory location. case 1: Static Allocation int array[10][20]; int *parray; parray = &array; e.g. - note that *(p+(i*3) +j) in the printf statement has (i*3) to manipulate the array location.