🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Pointers and 2D Arrays: all 15 questions

Quiz: Pointers and 2D Arrays · Question 15 of 15

A matrix is stored in one malloc block of rows × cols ints, int a. How do you reach row i, column j?

A matrix is stored in one malloc block of rows × cols ints, int *a. How do you reach row i, column j?

  1. A.a[i][j]
  2. B.a[j * rows + i]
  3. C.a[i * cols + j]
  4. D.a[i + j]
Answer & explanation

Correct answer: a[i * cols + j]

Row-major layout: skip i full rows of cols elements, then move j places along the row.

Can you get the rest right without peeking?

Take the timed Quiz: Pointers and 2D Arrays quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →