Array storing numbers in a list one by one

How do I store numbers in an array like a list one by one?
example if i do:

int d[3];

void loop
{
  if(blabla){
    d[3]= {1}
  }
}

and then when it loops, I want the output to be d[3]={1,1,1}
How do I do that? The code above seems wrong

    d[3]= {1}

This will work but the braces are not needed

An example :

byte anArray[16];
const byte NUMBER_OF_ELEMENTS = sizeof(anArray) / sizeof(anArray[0]);

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  for (int index = 0; index < NUMBER_OF_ELEMENTS; index++)
  {
    anArray[index] = random(256);
  }
  for (int index = 0; index < NUMBER_OF_ELEMENTS; index++)
  {
    Serial.print(index);
    Serial.print("\t");
    Serial.println(anArray[index]);
  }
}

void loop()
{
}

UKHeliBob:

    d[3]= {1}

This will work but the braces are not needed and will f*u the memory because d[3] isn't declared.
[/quote]
Because you only declared d[0], d[1] and d[2] :wink:

septillion:
Because you only declared d[0], d[1] and d[2] :wink:

My fault for not explaining that whilst it will work in general it is incorrect in the case of the OP's code

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.