in Programming in C recategorized by
9,613 views
6 votes
6 votes

Consider a $2$-dimensional array $x$ with $10$ rows and $4$ columns, with each element storing a value equivalent to the product of row number and column number. The array is stored in row-major format. If the first element $x[0][0]$ occupies the memory location with address $1000$ and each element occupies only one memory location, which all locations (in decimal) will be holding a value of $10$?

  1. $1018,1019$
  2. $1022,1041$
  3. $1013,1014$
  4. $1000,1399$
in Programming in C recategorized by
by
9.6k views

4 Comments

Address of [Lr........n][Lc......m]th element in row major order =B+W[n(I−Lr)+[J−Lc]]

B-Base address

W=element size

n=number of rows

Lr is the first row number, Lc is the first column number.

10 =10*1

10=5*2

In 10*1, i=10 and j=1

1000+1((10-0)*4+(1-0))=1041

In 5*2 i=5 and j=2

1000+1((5-0)*4+(2-0))=1022

hence B is correct
1
1
If you're considering starting index from 0 then row will go upto 9 .

So 2 possibilities 5*2 and 2*5
1
1
But, there is only 4 column in question .so 5*2 is not possible
1
1

6 Answers

5 votes
5 votes
we can only get 10 from following combinations:

1*10 -- NOT POSSIBLE

10*1 -- POSSIBLE(take combination x[9][0])

2*5 --NOT POSSIBLE

5*2 -- POSSIBLE (x[4][1])

 

x[9][0] = 9*4+0+1000 = 1036

x[4][1]=4*4+1+1000=1017

I think this can be one of the answers

1 comment

why we are multiplying 9 with 4 in x[9][0] = 9*4+0+1000 = 1036

0
0
2 votes
2 votes
Option B is correct

10 = 10*1,5*2

      =1*10,2*5  is not possible because maximum 4 column

So

X[10]*[1]=1000+1[4(10-0)+(1-0)]

               =1000+41=1041

X[5]*[2]=1000+1[4(5-0)+(2-0)]

           =   1000  +22=1022

1 comment

yes its correct
0
0
0 votes
0 votes

Since each cell of 2D array say A[10][4] storing a value equivalent to the product of row number and column number...

.

For a location(cell) to hold a value of 10 the row and column must be of the form 1*10, 10*1, 2*5 or 5*2...

.

From these 4 values of rows and columns we can eliminate 1*10 and 2*5 as these values are falling out of the given array data... As value of column is >4 

.

So now we have to find the position for 10*1 and 5*2...

As BA for A(0)(0) is 1000...

Address for 10*1 = 1000+9*4+1 =1037

Address for 5*2 = 1000+ 4*4+ 2 = 1018

.

So answer should be 1018 and 1037 which is not in any option...

by

3 Comments

from where you get 10*1.. array start from x[0][0] and end with x[9][3]
0
0
here 10*1 just means 10th row and 1st column, it is represented in array format as A[9][0]
0
0
it is starting from x[0][0] so no need to minus 1 from i and j.
0
0
0 votes
0 votes
I got the 1018 and 1037 address  

in the problem, 10 will appear only  2 times that is x[1][10] and x[2][5]

x[1][10] = 1037
x[2][5] = 1018

1 comment

This is not possible because maximum 4 column

Only possible 10*1 and 5*2
0
0
Answer:

Related questions