1D & 2D Arrays, Memory Layout & Array Algorithms
Understand contiguous array memory layout, 1D/2D arrays, array decay when passing to functions, reversal, rotation, and std::array.
- random access via
*(arr + i). 2D arraysint mat[R][C]are stored in row-major order in memory (row 0 followed by row 1), making row-wise traversal cache-friendly. - it to
int*, losing its size. Preferstd::array<int, N>(fixed size, knows.size(), supports.at()bounds checking) orstd::vector<int>(dynamic size).
1. Contiguous Memory Layout & Row-Major 2D Arrays
Arrays store elements in contiguous memory, giving O(1) random access via *(arr + i). 2D arrays int mat[R][C] are stored in row-major order in memory (row 0 followed by row 1), making row-wise traversal cache-friendly.
2. Array Decay & Modern `std::array` / `std::span`
Passing a C-array int arr[] to a function decays it to int*, losing its size. Prefer std::array<int, N> (fixed size, knows .size(), supports .at() bounds checking) or std::vector<int> (dynamic size).
3. Common Array Algorithms
Reversal, rotation, duplicate detection, searching, and sorting (std::sort).
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)