ProgrammingHard

In row-major order, the cell a[i][j] of a matrix with C columns sits at which flat index?

  1. A. i * C + j
  2. B. j * C + i
  3. C. i + j * R
  4. D. i * R + j

Correct answer: A. i * C + j

Each row has C elements, so row i starts at i * C and column j adds j. The other forms use the wrong dimension or swap the indices.

More C Programming questions

Exams that ask this topic