0

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?

2

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Yes. Let break it down a little

array<int, SIZE_INNER>

Is going to create an array of size SIZE_INNER. Now you wrap that array in

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

So the inner array is your "column" and the outer array is your "row". Just like with plain 2d arrays.

When working with the [] operator the one farthest to the right is for the inner most array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.