recategorized by
9,739 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$
recategorized by

6 Answers

0 votes
0 votes
Locations holding value 10 is only (5,2) because all other possibilities like (2, 5), (1, 10), (10, 1) lead to array overflows as this array has 10 rows, 4 columns which are 0-indexed.

As the array is stored in row-major format, We have to travel 5 rows of 4 columns from the base address and then in that row travel 2 columns to get the required location.

Now, Address of arr[5][2] = 1000 + 5 * 4 + 2 = 1022.

So (b) options has 1022, but 1041 location is incorrect because it lies outside the array as 1041 = 1000 + 10 * 4 + 1,  where 1040 = 1000 + 10 * 4 is the last location in array.

So no option is correct.
0 votes
0 votes
as given in the questions there is 2 options so you can take 10*1 also and there must be 5*2 too. so there correct option is B.
Answer:

Related questions

6 votes
6 votes
5 answers
1
Satbir asked Jan 13, 2020
3,831 views
What is the output of the code given below?# include<stdio.h int main() { char name[]="satellites"; int len; int size; len= strlen(name); size = sizeof(name); printf("%d"...
2 votes
2 votes
3 answers
2
Satbir asked Jan 13, 2020
1,820 views
Consider the following recursive C function that takes two argumentsunsigned int rer(unsigned int n, unsigned int r){ if(n>0)return(n%r + rer(n/r,r)); else retturn 0; }Wh...
6 votes
6 votes
1 answer
3