The Gateway to Computer Science Excellence
+1 vote
150 views

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 by Veteran (75k points)
edited by | 150 views

3 Answers

+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
by Active (1.3k points)
selected by
0 votes
None of these answer is 2832.
by (243 points)
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

by Loyal (7k points)
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,397 answers
198,611 comments
105,456 users