Pages: [1]   Go Down
Author Topic: Help with Arrays  (Read 508 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-wink !
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26471
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 218
You will become one with the Arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: