1,590 views

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.

no

it is 3,6

a[1] ==> a means 0th 2D , a+1 means 1st 2D ==> *(a+1) means 0th 1D of 1st 2D

a[0] ==> a means 0th 2D ==> *(a+0) means 0th 1D of 0th 2D

a[1]-a[0] ===> what is the distance between them ?

0th 1D of 0th 2D --> 1st 1D of 0th 2D --> 2nd 1D of 0th 2D --> 0th 1D of 1st 2D

==> 3

similarly, a[1][0] = points to 0th element of 0th 1D of 1st 2D

a[0][0] = points to 0th element of 0th 1D of 0th 2D

a[1][0]-a[0][0] ===> what is the distance between them ?

0th element of 0th 1D of 0th 2D --> 1st element of 0th 1D of 0th 2D --> 0th element of 1st 1D of 0th 2D --> 1st element of 1st 1D of 0th 2D --> 0th element of 2nd 1D of 0th 2D --> 1st element of 2nd 1D of 0th 2D --> 0th element of 0th 1D of 1st 2D.

===> 6

May this help you all. See @27:12

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

a[1][2] = some value ..can be seen as

int x ;

&x = some value

which is invalid right ??
yes !
edited

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

@Deepanshu, @Shaik Masthan Is this line correct?? Considering the given size of 1d array is 2 i.e 0th 1d of 0th 1d array and 1st 1d of 0th 1-d array are indices (0 and 1 indices for array size of 2)possible if so then only 2 steps are required for it right????

Am sorry i was wrong .....got the concept and answer....Tnq a lot for both of you :D :D especially @Shaik Masthan foryour pictorial explanations..

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]