1,516 views

2 Answers

0 votes
0 votes

store the array in row major

1

2

3

4

5

6

7

8

9

10

11

12

0010

0210

0410

0610

0810

1010

1210

1410

1610

1810

2010

2210

now convert to 2d

arr[0]

100

202

304

406

508

610

arr[1]

712

814

916

1014

1116

1218

arr= arr+0 = 00 and arr[1]=arr+1=12  as (arr+1) gives the address of next 2D array in that 3D array. So arr[1]-arr[0] = (1210-0010)/ 2 =12/2 = 6 ( where 2 is the size of integer data type ).

Again , arr[1][0] =*(arr+1)+0 = 12 , i.e points to first row of second 2D array of this 3D array. arr[0][0]= *(arr+0)+0 = 100010.So arr[1][0]- arr [0][0] = (1210-0010)/ 2 =12/2 = 6

0 votes
0 votes

After running the code 

 

ANS is 3 6 which u can see in given image

(NOTE : X represents base value)

for given 3d array  have a 2*3 element in each layer

means each plane have total 6 element which means for a[1] have value  X+6*2=X+12

and for a[0]=X+0*2=X;

similar for a[1][0] and a[0][0]

a[1]-a[0] = (X+12-X)/4(size of row which have 2 element) = 3

a[1][0]-a[0][0] = (X+12-X)/2(size of each element) =  6

edited by

Related questions

1 votes
1 votes
2 answers
4
Shamim Ahmed asked Dec 11, 2018
1,240 views
Given a 2D array A[40….95, 40...95] in lower triangular representation, size of each element is 1 ByteArray implemented in row major order, base address is 1000Address ...