CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Stupid question about arrays

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Tonwo
Guest







Stupid question about arrays
PostPosted: Thu Apr 26, 2007 4:05 am     Reply with quote

I have this problem when I work with arrays,I want to create an array, and later I want to give values.


I know I can do this:

int a[2]={3,6};

but why I cant do this?

int a[2]
.
.
.
a={3,6};
frequentguest
Guest







PostPosted: Thu Apr 26, 2007 7:25 am     Reply with quote

because it's not correct C syntax...
[code]
a[0]=3;
a[1]=6;
[/code]
is the most simple way to do it, but there are dozens of ways of performing this behavior.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Apr 26, 2007 8:21 am     Reply with quote

You need to give exact instructions on where you want each value to be stored. An array is a group of numbers that have a common reference but each location is considered to be an individual variable. Simply stating

a = {3,6};

doesn't say where you want each one to be placed. If you had an array

a[100]

and you wanted a value of 100 placed in location a[90] you would need to specify that it be placed there. You're wanting the program to 'assume' you want the numbers placed at the lowest location, in order. You can't do this. You need to specify, exactly, what you want to do with no assumptions allowed. You need to write:

a[90] = 100;

As with your example, you can declare:

int a[2];

Then stuff values into it:

a[0] = 3;
a[1] = 6;

That's just the way it is.

Ronald
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group