Machine-translated by Google. Questions are authored in English.
Top

Discussion

A two dimensional array B of 4 byte elements has 10 columns and lower bounds of zero. In row major order, what offset does B[2][3] occupy?

  • A.50
  • B.12
  • C.92
  • D.23

Answer: C

Row-major order lays each row out contiguously, so the linear index counts whole rows first: \[ \text{index} = i \times n_{cols} + j = 2 \times 10 + 3 = 23 \] \[ \text{offset} = 23 \times 4 = 92 \ \text{bytes} \] Column-major order would compute \( j \times n_{rows} + i \) instead, which is why the same subscript addresses different memory in Fortran and in C.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.