Search code examples
c++stdarray

Indexing into std::array of std::array


I have some confusion about indexing of an array of arrays in C++:

I have:

array<array<int, SIZE_INNER>, SIZE_OUTER> arr;

When I do indexing, I assume the following:

arr[outer_index][inner_index]

So, outer_index into the array with SIZE_OUTER comes first, and the inner index then comes second.

Is that true?


Solution

  • Yes. Think like this: arr[o] accesses the o-th element of arr. The fact that the element is an array too doesn't change much.

    Subsequent calls to operator [] access elements returned by previous calls.