← 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?
- A.a[i][j]
- B.a[j * rows + i]
- C.a[i * cols + j]
- 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 →