Pages: [1]   Go Down
Author Topic: setting value of multi-dimension array?  (Read 895 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 296
Got Karma?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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:
 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?

tx!
  
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 285
Posts: 25632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can only do:
Code:
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.
« Last Edit: January 10, 2010, 01:41:15 pm by AWOL » Logged

"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.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 296
Got Karma?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok - thanks!
Logged

Pages: [1]   Go Up
Jump to: