Row-major: int m[ROWS][COLS] is stored as all of row 0's columns, then all of row 1's, contiguously, there's no array of row pointers, it's one flat block. The compiler maps m[r][c] to the linear offset r * COLS + c. When you manage a flat buffer yourself, common in embedded for framebuffers or sample matrices, you replicate that: buf[r * cols + c]. You must use the column count as the multiplier (the width of a row), and keep r/c in the right order, or you'll read the wrong element or go out of bounds. Wrapping it in an accessor like at(buf, cols, r, c) centralizes the arithmetic and avoids the classic transposed-index bug.
Data Structures & Algorithms · Interview question
How is a 2D array laid out in memory in C, and how do you index a flat buffer as 2D?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Arrays & Memory Layout
Contiguous storage is why arrays give O(1) indexing and why row-major traversal is cache-friendly, plus array-of-structs vs struct-of-arrays for embedded data.