347 views
1 votes
1 votes

1 Answer

Best answer
1 votes
1 votes

if code is 

#include <stdio.h>

int main(void) {
    int arr[2][3][2]= {{{1,2},{3,4},{5,6}},{{7,8},{9,10},{11,12}}};
    printf("%d %d",arr[1]-arr[0],arr[1][0]-arr[0][0]);
    return 0;
}

arr points to 0th element of arr, which is whole 2D array {{1,2},{3,4},{5,6}}

arr[1] means *(arr + 1), 

arr+1 means 2nd element of arr which is 2d array {{7,8},{9,10},{11,12}} 

then accessing the first element of 2d array by referencing it. which is {7,8}

similarly arr[0] will point to {1,2}

and arr[1] - arr[0] will given the amount of 1D arrays between then, 

So arr[1] - arr[0] will return $\large 3$ 

$arr[1][0] - arr[0][0]$

$arr[1][0]$ means $^*(^*(arr + 1) + 0)$

$^*(arr + 1)$ points to {7,8} derefrening it again will give 1st element of {7,8} which is 7 but we are not derefrencing again. So $^*(^*(arr + 1) + 0)$ is giving address of $7$.

Similarly  $^*(^*(arr + 0) + 0)$ will give address of $1$

$arr[1][0] - arr[0][0]$ will give number of int elements between 1 and 7. which are $6$

selected by

No related questions found