Go Down

Topic: setting value of multi-dimension array? (Read 1 time) previous topic - next topic


Hi - was thinking I could set the value of a mult-dimensional array in one go - something like this:

Code: [Select]
int test[5][3];

void setup(){
test[1] = {1,1,1};

But that throws the error error: expected primary-expression before '{' token

Tried some variations:
test[1] = [1,1,1]; etc. with same error. The value of test[1] is an array of 3 ints so I am not getting why I can't set it directly. I know I can do this:

Code: [Select]
 test[1][0] = 1;
 test[1][1] = 1;
 test[1][2] = 1;

But that seems very clumsy. Am I missing something or is this just not possible?



Jan 10, 2010, 07:40 pm Last Edit: Jan 10, 2010, 07:41 pm by AWOL Reason: 1
You can only do:
Code: [Select]
int test[2][3] = {{1,2,3},{3,4,5}} ;
when the variable is declared, otherwise, yes, you're (mostly) stuck with initialising individual elements.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up