edited by
30,000 views
45 votes
45 votes

Let $A$ be a two dimensional array declared as follows:

A: array [1 …. 10] [1 ….. 15] of integer;

Assuming that each integer takes one memory location, the array is stored in row-major order and the first element of the array is stored at location $100$, what is the address of the element $A[i][j]$?

  1. $15i+j+84$

  2. $15j+i+84$

  3. $10i+j+89$

  4. $10j+i+89$

edited by

8 Answers

5 votes
5 votes

$a$        $\underbrace{[10]}$            $\underbrace{[15]}$

        $streets$       $buildings$

Now you want to go and meet a friend who lives on $j^{th}$ building of $i^{th}$ street means $a[i][j]$

So, firstly cross $(i-1)$ streets each consist of $15$ buildings: $(i-1)\times 15=15i-15$

Now cross $(j-1)$ buildings in order to reach your destination: $j-1$  

$Ans: RMO: 100+15i-15+j-1=>15i+j+84$


$a$        $\underbrace{[10]}$            $\underbrace{[15]}$

    $buildings$       $streets$

Now you want to go and meet a friend who lives on $i^{th}$ building of $j^{th}$ street means $a[i][j]$

So, firstly cross $(j-1)$ streets each consist of $10$ buildings: $(j-1)\times 10=10j-10$

Now cross $(i-1)$ buildings in order to reach your destination: $i-1$  

$Ans: CMO: 100+10j-10+i-1=>10j+i+89$

1 votes
1 votes

When the initial element of the array is at A[0][0] to reach A[i][j] we skip i rows and j columns.

But here, the initial element is at A[1][1]. So, we'll skip (i-1) rows and (j-1) columns.

 

$100+(i-1)*15+(j-1)$

=> $100+15i-15+j-1$

=> $84+15i+j$

 

Option A

0 votes
0 votes

To find address of any element in an array

base address + (no. of elements before the elements whose address we want to find)* size of each element

here array [1 …. 10] [1 ….. 15]

we want to find address of $A[i][j]$ considering row major order

to reach  ith row we have to cross  $i-1$ rows as starting index is 1

no. of elements = (i-1)*elements in each row(=no.of columns)

                          =$i-1*15$

                          =$15i-15$

to reach jth element in ith row we have to cross j-1 elements in ith  row 

total elements to cross to reach $A[i][j]=15i-15+j-1$

address of $A[i][j]$ = $100-16+15i-j$

                             =$15i+j+84$

OPTION A

 

0 votes
0 votes

(A.)  100 +[(i-1)*15 + (j-1)]*1

     = 100+[15i –15+j-1]*1

    = 100+15i-16+j

       15i+j+84 .

 

Answer:

Related questions

24 votes
24 votes
1 answer
1
Kathleen asked Sep 25, 2014
9,153 views
A multiplexer with a $4-bit$ data select input is a$4:1$ multiplexer$2:1$ multiplexer$16:1$ multiplexer$8:1$ multiplexer
29 votes
29 votes
11 answers
2
Kathleen asked Sep 25, 2014
14,797 views
A complete $n$-ary tree is one in which every node has $0$ or $n$ sons. If $x$ is the number of internal nodes of a complete $n$-ary tree, the number of leaves in it is g...
22 votes
22 votes
3 answers
4
Kathleen asked Sep 25, 2014
9,189 views
Which of the following operations is commutative but not associative?ANDORNANDEXOR