Go Down

Topic: Help with Arrays (Read 534 times) previous topic - next topic

mario595

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  ;) !

AWOL

There's nothing wrong with the code you posted.
Can you post the whole thing?
"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.

mario595

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!

Manny

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

Spinlock

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:
Code: [Select]

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

Go Up