edited by
2,170 views
6 votes
6 votes

int arr[2][3][2];

print(arr[1]-arr[0],arr[1][0]-arr[0][0])

P.s :Sorry i can't able to paste the question but this is main Context.

edited by

2 Answers

8 votes
8 votes

FIRST lof all lets understand what these a, a[0] and a[0][0] means

arr [2] [3] [2] means we have 2 planes in those planes 3 rows and  2 columns

A)   when we simply mention arr  it means arr is a 3d array ===> collection of 2D array's ===> Base address of 0th 2-D address will give as a result.

B) when we mention a[0] means we are derefrencing it  and it means we are pointing to 0th 1-D array of 0th 2-D array 

C) when we mention a[0][0] means dereferncing further more one step so now it points to oth element of 0th 1-D array of 0th 2-D array 

D) when we mention a[0][0][0] means now we refer to the value of oth element of 0th 1-D array of 0th 2-D array 

 

now see a[1] = *(a+1) ===> *(0th 2-D array + 1) ===> *(1st 2-D array) ===> 0th 1-D of 1st 2-D array

now see a[0] = *(a+0) ===> *(0th 2-D array) ===> 0th 1-D of 0th 1-D array

a[1] - a[0] it is valid if both are point to same array and same size of dimensions, is it valid ? yes, both are pointing in same array and have same size as 1-D then what it means

a[1] - a[0] means how much away a[1] is to a[0] ?

there are 3 steps away.

i.e.,  0th 1-D of 0th 1-D array ---> 1st 1-D of 0th 1-D array ---> 2nd 1-D of 0th 1-D array ---> 0th 1-D of 1st 2-D array

 

now see a[1][0] = *( *(a+1)+0) ) ===> *( *(0th 2-D array + 1) ) ===> *( *(1st 2-D array) ) ===> *( 0th 1-D of 1st 2-D array ) ===> 0th element of 0th 1-D of 1st 2-D array

now see a[0][0] = *( *(a+0) ) ===> *( *(0th 2-D array) )  ===> *( 0th 1-D of 0th 1-D array ) ===> 0th element of 0th 1-D of 0th 2-D array

a[1][0] - a[0][0] it is valid if both are point to same array and same size of dimensions, is it valid ? yes, both are pointing in same array and have same size as element then what it means

a[1][0] - a[0][0] means how much away a[1][0] is to a[0][0] ?

there are 6 steps away.

i.e., 0th element of 0th 1-D of 0th 1-D array ---> 1st element of 0th 1-D of 0th 1-D array ---> 0th element of 1st 1-D of 0th 1-D array ---> 1st element of 1st 1-D of 0th 1-D array ---> 0th element of 2nd 1-D of 0th 1-D array ---> 1st element of 2nd 1-D of 0th 1-D array ---> 0th element of 0th 1-D of 1st 2-D array

edited by
0 votes
0 votes

Above 3D array, we can write like this 

array[0] => [0] => [0, 1]
            [1] => [0, 1]
            [2] => [0, 1]
array[1] => [0] => [0, 1]
            [1] => [0, 1]
            [2] => [0, 1]
array[2] => [0] => [0, 1]
            [1] => [0, 1]
            [2] => [0, 1]

Clearly Here A[1] and A[0] are 3 steps away.

A[1][0] and A[0][0] are 6 Steps away.

For 4 D array you can write like this.  

int array[2][3][2][5];
array[0] => [0] => [0] => [0, 1, 2, 3, 4]
                   [1] => [0, 1, 2, 3, 4]
            [1] => [0] => [0, 1, 2, 3, 4]
                   [1] => [0, 1, 2, 3, 4]
            [2] => [0] => [0, 1, 2, 3, 4]
                   [1] => [0, 1, 2, 3, 4]
array[1] => [0] => [0] => [0, 1, 2, 3, 4]
                   [1] => [0, 1, 2, 3, 4]
            [1] => [0] => [0, 1, 2, 3, 4]
                   [1] => [0, 1, 2, 3, 4]
            [2] => [0] => [0, 1, 2, 3, 4]
                   [1] => [0, 1, 2, 3, 4]

 

Related questions

1 votes
1 votes
1 answer
2
Sourabh Kumar asked Jul 25, 2016
356 views
3 votes
3 votes
2 answers
3
Anjan asked Jan 8, 2018
6,283 views
Consider 3 dimensional Array A[90] [30] [40] stored in linear array. If the base address starts at 10, The location of A [20] [20] [30] in case of RMO and CMO are _______...
4 votes
4 votes
3 answers
4
Hira Thakur asked Nov 19, 2017
871 views
#include<stdio.h int main() { int arr [3] ={{{2,4},{7,8},{3,4},},{{2,2},{2,3},{3,4},}}; print("\n%d", (*arr+1)+2+7); return 0; } plz explain this program, internally how ...