-2

For the following value-of an array, I can do:

array[i][j][k] = *(*(*(array+i)+j)+k);
---------------------------------

int xar[3] = {1,2,3};
printf("%d | %d\n", xar[1], *(xar+1));

int xar2[2][3] = {{1,2,3}, {4,5,6}};
printf("%d | %d\n", xar2[1][2], *(*(xar2+1)+2));

int xar3[2][2][2] = {
                      {{1, 2},{3, 4}}, 
                      {{5, 6}, {7, 8}}
                    };
printf("%d | %d\n", xar3[1][1][1], *(*(*(xar3+1)+1)+1));

2 | 2
6 | 6
8 | 8

However, I'm having a tougher time trying to get the address of an array element and why that works, for example, if I have:

&array[i][j][k];

array+i gives me the equivalent of &array[i], but then how would I grab the full inner item?

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
David542
  • 104,438
  • 178
  • 489
  • 842

1 Answers1

2

Note that &*array will cancel each-other out, so we can do:

 array[i][j][k] =  *(*(*(array+i)+j)+k);
&array[i][j][k] = &*(*(*(array+i)+j)+k);   // &* can be eliminated
&array[i][j][k] =    *(*(array+i)+j)+k;
David542
  • 104,438
  • 178
  • 489
  • 842