#include <stdio.h>
int main(int argc, char const *argv[]) {
/* code */
int a[2][3][2] = {{{1,2},
{9,8},
{3,7}},
{{2,2},
{1,4},
{5,4}}};
int i,j,k;
printf("\n\n\n");
for (i = 0; i < 2; ++i) {
for (j = 0; j < 3; ++j) {
for (k = 0; k < 2; ++k) {
printf("\t &a[%d][%d][%d] = %p ",i,j,k,(&a[i][j][k]) ) ;
}
printf("\n");
}
printf("\n");
}
printf("\t a[1] = %p a[0] = %p\n",a[1],a[0] );
printf("\t a[1] - a[0] = %d\n",a[1] - a[0] ); // ????
printf("\t a[1][0] = %p a[0][0]= %p\n",a[1][0],a[0][0] );
printf("\t a[1][0] - a[0][0] = %d\n", a[1][0] - a[0][0]); // ??????
return 0;
}
O/P:
&a[0][0][0] = 0023FF04 &a[0][0][1] = 0023FF08
&a[0][1][0] = 0023FF0C &a[0][1][1] = 0023FF10
&a[0][2][0] = 0023FF14 &a[0][2][1] = 0023FF18
&a[1][0][0] = 0023FF1C &a[1][0][1] = 0023FF20
&a[1][1][0] = 0023FF24 &a[1][1][1] = 0023FF28
&a[1][2][0] = 0023FF2C &a[1][2][1] = 0023FF30
a[1] = 0023FF1C a[0] = 0023FF04
a[1] - a[0] = 3
a[1][0] = 0023FF1C a[0][0]= 0023FF04
a[1][0] - a[0][0] = 6
I understand the decay of pointers. In the above code a[1] and a[0] both decay to the first locations of each 2d arrays, inside actual array a.
When we take the difference of these two pointers they behave like pointers to 1d array ((int*)[]) of 2 elements.
because we are dealing with a 3d array in this c program, we four types of possible pointer types.
(int*)[][][](int*)[][](int*)[](int*)
In terms of pointer's value, all types decay into single element location.
My doubt is, even after decay what are possible TYPES of a[],a[][],&a,a etc. which can produce different result. (as in the case of pointer difference in the above program)