//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
Discussions

How to pass a 2D array by pointer in C? - Stack Overflow
You need to change the definition ... it a 2D array: ... Sign up to request clarification or add additional context in comments. ... could you explain what the syntax "char *array[50]" means in plain english? 2013-05-23T21:43:41.123Z+00:00 ... Running cdecl explain 'char (*arr)[50]' yields declare arr as pointer to array 50 ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to get a pointer to 2D array when writing a C source Mex file?
You would need to set up a separate pointer array in order to use this syntax (never worth it IMO), or just do the indexing calculations manually (my preference). ... Since the 2D matrix is stored column-wise and the vector is on the left of the multiply, you can access the 2D matrix in a simple ... More on mathworks.com
๐ŸŒ mathworks.com
2
0
July 19, 2018
c - Pointer to 2D Array
That is the type of expression *(gPtr1 + 3) is int[3] and there are only three such elements in the oridinal arrays. ... In this case using the pointers the arrays are interpretated as one-dimensional arrays with 9 elements and expressions More on stackoverflow.com
๐ŸŒ stackoverflow.com
pointer to 2d array - C++ Forum
Your code declares int** a, which ... to an int, not a pointer to any array. Seeing as you're trying to compile arry = a, it sounds like you're looking for a pointer to a row, which is what you get if you use a on the right side of assignment: What's your use case anyway, why do you need this? ... Multidimensional arrays are evil. Syntax poison. http://www.cplusplus.com/forum/articles/17108/ That said... This doesn't work because a "pointer to a pointer" is not the same thing as a "2D ... More on cplusplus.com
๐ŸŒ cplusplus.com
October 23, 2013
๐ŸŒ
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?

๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 177473-passing-pointer-2d-array-function.html
passing a pointer to a 2d array to a function
April 28, 2019 - 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.
๐ŸŒ
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; }
๐ŸŒ
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.
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);
...
๐ŸŒ
Codedamn
codedamn.com โ€บ news โ€บ c programming
How to use pointers with 2D arrays in C?
March 10, 2024 - The syntax for declaring a 2D array in C is as follows: ... While array notation is straightforward and familiar to most, pointer notation offers a more powerful and flexible way to interact with arrays and their elements.
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).
๐ŸŒ
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.).
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ explain-pointers-and-two-dimensional-array-in-c-language
Explain pointers and two-dimensional array in C language
March 17, 2021 - 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 ( ); }
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_pointers_arrays.php
C Pointers and Arrays
Well, in C, the name of an array, is actually a pointer to the first element of the array.
๐ŸŒ
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.
๐ŸŒ
Cplusplus
cplusplus.com โ€บ forum โ€บ beginner โ€บ 114553
pointer to 2d array - C++ Forum
October 23, 2013 - Your code declares int** a, which is a pointer to a pointer to an int, not a pointer to any array. Seeing as you're trying to compile arry = a, it sounds like you're looking for a pointer to a row, which is what you get if you use a on the right side of assignment: What's your use case anyway, why do you need this? ... Multidimensional arrays are evil. Syntax poison. http://www.cplusplus.com/forum/articles/17108/ That said... This doesn't work because a "pointer to a pointer" is not the same thing as a "2D array".
๐ŸŒ
Quora
quora.com โ€บ How-do-you-pass-a-2D-array-to-a-function-with-pointers
How to pass a 2D array to a function with pointers - Quora
Answer (1 of 3): #1023 - COMP SCI - C PASS 2D ARRAY TO FUNCTION WITH POINTERS Letโ€™s do it! Our C program as per problem specifications: [code]// C program passing 2D array to a function with pointers #include #include // Print 2D array elements void fnPrint2DArray(int ...