 # multidimensional array

I have a multidimensional array, but the number of values is not fixed.

{0},{1,9},{2,8,10}

this doesn’t work : int columns = {{0},{1,9},{2,8,10}};

this compiled : int columns = {{0},{1,9},{2,8,10}};

But in my loop, if I use sizeof() it always returns 3, even if I have less values :

for( int i = 0; i < 3; i++) {
int numLeds = sizeof(columns*) / sizeof(int);*

• Serial.println(numLeds);*
• delay(1000);*
• for( int j = 0; j < numLeds; j++) {*
I was thinking of another way
col1 = {0};
col2 = {1,9};
col3 ={2,8,10}
but I can’t use a loop since there is no eval() function in arduino :
for( int i = 0; i < 3; i++) {
• arrayColumns = eval(‘col’ + i)*
Is there a way to do this in a dynamic manner, i would like to avoid writing code for every array …
Thank you

C and C++ don't do non-rectangular arrays.

You can have a list of pointers to lists:

``````int column1[] = {0};
int column2[] = {1,9};
int column3[] = {2,8,10};
int *columns[] = {column1, column2, column3};
``````

The problem with that is that it only allow you to get the length of the first level: sizeof columns / sizeof columns == 3

But you can't get the length of each column because you can't use sizeof through a pointer: sizeof columns == 2 (the size of an int pointer) sizeof columns == 2 (the size of an int)

You could store the length of each column in the lists:

``````int column1[] = {1, 0};
int column2[] = {2,1, 9};
int column3[] = {3, 2, 8, 10};
int *columns[] = {column1, column2, column3};
``````

Or you could put EOL markers in each list: You could store the length of each column in the lists:

``````int column1[] = {0, -1};
int column2[] = {1, 9, -1};
int column3[] = {2, 8, 10, -1};
int *columns[] = {column1, column2, column3};
``````