Two-dimensional array with leading elements c ++

0

Hi, I have to make an array of this type arr [32] [64] where each element is a pointer.

I need to make a 32x64 matrix. Each element of that matrix is a pointer to a linked list.

I do not know how to declare it.

    
asked by Franco 27.10.2018 в 17:12
source

1 answer

1

To assign a matrix or dimensional array to a pointer of the same type you can use double cycle and achieve the assignment.

int *puntero[32][64]; //matriz de punteros 
int a[32][64]; //matriz.

Now we will see that a matrix of pointers can contain a two-dimensional array. Continuing the above:

int i; 
int j;
for (i=0;i<32;i++){ 

for (j=0;j<64;j++){
puntero[i][j]=&a[i][j]; //Asignamos los valores al puntero. 
}

}

As we saw in this way, we keep, as it were, a two-dimensional array in a pointer.

Note: It is possible to save it in a one-dimensional array pointer if we assign each row a position in the array .

    
answered by 27.10.2018 в 17:31