Multidimensional array initialisation

Hello forum, a simple syntax question.

I have a two dimensional array which I can both declare and initialise simultaneously like so:

int joystick1[2][3] = {{0, 1023, 0},
** {0, 1023, 0}};** // this works

I 'd like to separate this into two separate statements, like:

int joystick1[2][3]; // this works

and something like:

joystick1 = {{0, 1023, 0},
** {0, 1023, 0}};** // Aargh!!!
which always crashes and burns with:

"error: expected constructor, destructor, or type conversion before '=' token"

So, does anyone know if I can initialise an already declared array using the {blah, blah, blah...} syntax as opposed to having to fill it in by hand, element by element?

So, does anyone know if I can initialise an already declared array using the {blah, blah, blah...} syntax as opposed to having to fill it in by hand, element by element?

Unfortunantly, that is not possible.

You could do this:

int joystick1[2][3];

/*
  LATER IN YOUR CODE
*/
//prepare values
int buffer[2][3] = {
  {0, 1023, 0},
  {0, 1023, 0}
};

//fill array
for (int x=0; x<2; x++){
  for (int y=0; y<3; y++){
    joystick1[x][y] = buffer[x][y];
  }
}

BTW: Welcome to the community! :slight_smile:

Sneaky idea :wink: thank you.