1

I'm trying to make an array which contain int[][] items

i.e

int version0Indexes[][4] = { {1,2,3,4}, {5,6,7,8} };
int version1Indexes[][4] = { ...... };

int version15Indexes[][4] = { ... };

(total of 16)

int indexes[][][] = { version0Indexes,version1Indexes, .. };

anyone can suggest how to do so ?

Thanks

2
  • If you don't know how big an array will be at runtime, you have to allocate the array on the heap. Commented Mar 30, 2015 at 8:34
  • 1
    Do you want contiguous memory or array of pointers ? Commented Mar 30, 2015 at 8:35

2 Answers 2

2

You can use an array of pointers to array:

int (*indexes[])[4] = { version0Indexes, version1Indexes, .. };
Sign up to request clarification or add additional context in comments.

Comments

2

Either you inline your arrays inside indexes:

int indexes[][2][4] = {
    { { 1, 2, 3, 4}, {5, 6, 7, 8} },
    { {....}, {....} }
    ....
}

Or you make indexes an array of pointers:

int (*indexes[])[4] = { version0Indexes, version1Indexes, .... };

What you wrote in your question is not directly possible because, when used, an array variable is actually a pointer (that's why indices has to be an array of pointers).

1 Comment

int indexes[][][4] is an array of incomplete type and will not compile.

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.