I am trying to manipulate the array prarr[3][3]
by using a pointer ptr_ptr_prarr
to an array ptr_prarr[3][3]
that contains pointers to prarr[3][3]
.
I would like to somehow point ptr_ptr_prarr
to ptr_prarr
and access the data in prarr[i][j]
by using something like ptr_ptr_prarr[i][j]
.
void main()
{
int prarr[3][3];
int count = 1;
for (int i = 0; i <= 2; i++)
for (int j = 0; j <= 2; j++)
prarr[i][j] = count++;
//printArray(prarr);
int *ptr_prarr[3][3];
for (int i = 0; i <= 2; i++)
for (int j = 0; j <= 2; j++)
ptr_prarr[i][j] = &prarr[i][j];
int n = 1, x = n, y = n;
printf("\nArray Coords:(%d,%d)\nMemory location:%p\nValue:%d",
x, y, ptr_prarr[x][y], *ptr_prarr[x][y]);
int **ptr_ptr_prarr= *ptr_prarr;
printf("\n");
for (int i = 0; i <= 8; i+=3)/* <<--------------------------------- */
{
for (int j = 0; j <= 2; j= (j+1))
printf("%d", (ptr_ptr_prarr[i][j]));
printf("\n");
}
Sleep(20000);
}
I think I've gotten close but for some reason ptr_ptr_prarr
requires the line containing "<<---------------------------------" : to iterate in a different fashion in order to replicate the original data.
Somehow I'm accessing something wrong and any help would be greatly appreciated!