# Assign value to a Multy Dimentional Array

I have the following array declared.

``````int cells = {
{0, 1, 0, 1},
{1, 0, 1, 0},
{1, 1, 1, 1},
{0, 0, 0, 0}
};
``````

Can I assign an array itself to an element like this, or how can I achieve this.

cells = {1, 1, 0, 0};

Thanks.

Why don't you just try it?

Are you only holding binary digits in your array? If so, do you know you are wasting 16 times more ram memory than you need to? Have a look at the bitRead() and bitWrite() functions.

Can I assign an array itself to an element like this, or how can I achieve this.

No
You can do

``````int cells =
{
{0, 1, 0, 1},
{1, 0, 1, 0},
{1, 1, 1, 1},
{0, 0, 0, 0}
};

void setup()
{
Serial.begin(115200);
cells = 1;
cells = 1;
cells = 0;
cells = 0;
}
``````

Note that the array index for both dimensions starts at 0 not 1 as your attempted code might suggest.

Thank you for the replies.

It might be worth mentioning that if you look at the two dimensional array as a table and want to replace one of the rows you can point to the row then write the new values in. Same result but another way of thinking about it.

``````  int row = 1;                  // index of row to replace
int *cellRow = cells[row];    // point to row
int newRow[] = {1, 1, 0, 0};  // new values

// write new values
for (c = 0; c < 4; c++) cellRow[c] = newRow[c];
``````