recategorized by
5,145 views
1 votes
1 votes

A three dimensional array in 'C' is declared as int A[x][y][z]. Here, the address of an item at the location A[p][q][r] can be computed as follows: (where w is the word length of an integer)

  1. &A[0][0][0]+w(y*z*q+z*p+r)
  2. &A[0][0][0]+w(y*z*p+z*q+r)
  3. &A[0][0][0]+w(x*y*p+z*q+r)
  4. &A[0][0][0]+w(x*y*q+z*p+r)
recategorized by

3 Answers

0 votes
0 votes
Answer B

Base address+ offseet
0 votes
0 votes

3D array can be considered like a cuboid

see following picture

 

we have to find address of A[p][q][r]

to reach pth frame we must cross 0 to p-1 frames i.e. p frames and each frame contains $y*z$ elements

= $y*z*p$

now to reach qth element in pth frame we have to cross q rows and each row contains z(total columns) elements

=$z*q$ 

to reach rth elements we have to cross r elements in (p+1)th row

total elements to cross =$(y*z*p+z*q+r)$

now each element occupies m amount of space 

therefore total space occupied by these elements = $m(y*z*p+z*q+r)$ 

so adress of $A[p][q][r]= base adress + Space Occupied by the Elements Before it.$

                                    =$ &A[0][0][0]+m(y*z*p+z*q+r) $

Option (B)

Answer:

Related questions

1 votes
1 votes
2 answers
2
6 votes
6 votes
2 answers
3
go_editor asked Aug 8, 2016
3,468 views
How many solutions are there for the equation $x+y+z+u=29$ subject to the constraints that $x \geq 1, \: \: y \geq 2 \: \: z \geq 3 \: \: and \: \: u \geq 0$?496026002375...
2 votes
2 votes
1 answer
4