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?

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? Correct Answer 1017, 1036

Each element is storing a value equivalent to the product of row number and column number to get 10 as the value

  • x = 1×10 = 10  //1st row and 10th column
  • x = 2 × 5 = 10   //2nd row and 5th column
  • x = 5 × 2 = 10  // 5th row and 2st column
  • x = 10 × 1 = 10 //10th row and 1st column


Out of this list, first two values are not possible as there are 4 columns only, ranging from 0 to 3.

Next two values are possible as 10 ≤ no. of rows ≤ 1 and 4 ≤ no. of rows ≤ 1. Now if row and column number starts at 0 then, the value 10 will be at,

int x;

x = A + (4n + m)× Size of cell

x = 1000 + (4(4) + 1)× 1 = 1017

x = 1000 + (4(9) + 0)× 1 = 1036

Important Point:

Option 3 has been changed:

Related Questions