Help with Arrays

Hi!
I'm trying to declarate an array and, later, add element to the array:

int array[3];
array[0]=1;
array[1]=2;
array[2]=3;

But I get this "error: expected constructor, destructor, or type conversion before ‘=’ token"

How can I do this??

Thanks :wink: !

There's nothing wrong with the code you posted.
Can you post the whole thing?

Ok, I've already seen the error. I was putting "array[0]=1" out of any function so I put it into the setup function.

Thanks!

Where you able to find out how to add another component to the array later?

Manny; You can't add an array later using that particular array's declaration. The array in the OP's post is allocated by the compiler. If you were to do this:

array[3]=1;

you would be writing over other memory, clobbering some other variable (perhaps)

There are other ways using malloc, realloc, etc. that can allocate space and reallocate space on the fly though - look them up...