in Programming edited by
403 views
1 vote
1 vote

A $2$-dimentional array is declared as  $A[-8 \text{ to } 12, \ -4 \text{ to } 16]$ , what will be the address of $A[1,3]$ if it is stored in row major order , each element occupies $4$ bytes and starting address of array is $2000$.

  1. $2784$
  2. $2776$
  3. $2794$
  4. $2764$
in Programming edited by
by
403 views

3 Answers

2 votes
2 votes
Best answer
Original matrix = A[lb1...ub1 , lb2..ub2]

n = size of column (ub2-lb2+1)

find address for A[i][j]

then for row major order,

[(i-lb1)*n + (j-lb2)]* size of each element +Base Address

thus A[1,3] = [(1+8)*21 + (3+4)]*4 +2000 = 784+2000 = 2784
selected by
0 votes
0 votes
None of these answer is 2832.
0 votes
0 votes

Normally, to access $A[1][3]$ we skip 1 rows and 3 columns. Because we assume the first element to be $A[0][0]$

 

But here, since the first element is at $A[-8][-4]$, to reach $A[1][3]$ skip 9 rows and 7 columns.

=> Skip 9 rows + 7 elements

=> Skip 9*(column length) elements + 7 elements

=> Skip 9(21) elements + 7 elements

=> Skip 189 elements + 7 elements

=> Skip 196 elements

=> Skip 196 * 4 bytes

=> Skip 784 bytes from the base address 2000.

=> 2784

 

Option A

Answer:

Related questions