Dark Mode

1,598 views

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.

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

it may help you

https://gateoverflow.in/282711/madeeasy-programming-language-2019?show=282720#c282720

1

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) ===> *(0^{th} 2-D array + 1) ===> *(1^{st} 2-D array) ===> 0^{th} 1-D of 1^{st} 2-D array

now see a[0] = *(a+0) ===> *(0^{th} 2-D array) ===> 0^{th} 1-D of 0^{th} 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., 0^{th} 1-D of 0^{th} 1-D array** --->** 1^{st} 1-D of 0^{th} 1-D array** ---> **2^{nd} 1-D of 0^{th} 1-D array **--->** 0^{th} 1-D of 1^{st} 2-D array

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

now see a[0][0] = *( *(a+0) ) ===> *( *(0^{th} 2-D array) ) ===> *( 0^{th} 1-D of 0^{th} 1-D array ) ===> 0^{th} element of 0^{th} 1-D of 0^{th} 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., 0^{th} element of 0^{th} 1-D of 0^{th} 1-D array** --->** 1^{st} element of 0^{th} 1-D of 0^{th} 1-D array** --->** 0^{th} element of 1^{st} 1-D of 0^{th} 1-D array** --->** 1^{st} element of 1^{st} 1-D of 0^{th} 1-D array** --->** ** **0^{th} element of 2^{nd} 1-D of 0^{th} 1-D array **--->** 1^{st} element of 2^{nd} 1-D of 0^{th} 1-D array** --->** 0^{th} element of 0^{th} 1-D of 1^{st} 2-D array

2

Shaik Masthan i think a means 3d array base address

simply mention a means, 0th 2-D base address

&a means it is base address of 3-D array

but i also see these statements many times thats why i am confused in past little.

i think we both trying same concept but you take A as base address of 2d array and from there address &A but i take simply A as 3d and then by DEREFERENCE i go to 2d array

0

0

edited
Oct 22, 2018
by Deepanshu

Shaik Masthan bro i am really not getting any idea what you are saying so just take my answer copy it and edit in the comment whereever you think i make mistake :)

i know this may be little big or taking more time but take your time to comment

0

0

0

0

edited
Jul 12, 2020
by Jithendra319

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**

@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..

0

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]
```