# Assignment of Two-Dimensional Arrays

• 08-06-2004
LuckY
Assignment of Two-Dimensional Arrays
Okay, this may seem a bit of an elementary question. If so, please forgive me.

I've initialized a two-dimensional array like so, for example:
Code:

```static const int 2DARRAY[2][3] = {   { 1, 2, 3 },   { 4, 5, 6 } };```
I have multiple arrays declared that way and depending on what level we want to load I need to generically access one of the 2D arrays and that's where I keep causing a page fault.

Before realizing my mistake I was trying something similar to this: "const int ***p2dArr = (const int***)2DARRAY;"

When I do a (*p2dArr)[0][0] I crash because the size of the array is unknown. How can I work around this limitation?
• 08-06-2004
you could place the 2D array in a struct/class and then have an container holding instances of the struct/class or you could create a 3D array, static or dynamic, as you need.

int threeDArray[4][2][3];

threeDArray[0] is the first of 4 2D arrays, each 2 by 3, that could be in threeDarray, etc.
• 08-06-2004
Salem
The notation for the pointer is exactly the same as if you were passing these arrays to a function
Code:

```#include <stdio.h> #include <stdlib.h> int main ( ) {     int one[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };     int two[2][3] = { { 7, 6, 5 }, { 4, 3, 2 } };     int (*p)[3];     int r,c;     p = one;     for ( r = 0 ; r < 2 ; r++ ) {         for ( c = 0 ; c < 3 ; c++ ) {             printf( "%d ", p[r][c] );         }         printf( "\n" );     }     return 0; }```
• 08-06-2004
manofsteel972
Code:

```static const int T2DARRAY[2][3] = {   { 1,2,3 },   { 4,5,6 } }; const int (*p2dARR)[3]=T2DARRAY; cout<< p2dARR[0][0];```
This works on Visual C++ compiler I had to change the name of the array because it starts with a number
• 08-06-2004
LuckY
It was surprisingly as simple as that... Thanks.