Public Group

Archived

This topic is now archived and is closed to further replies.

Arrays

This topic is 6035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I've seen some examples making something like this with arrays:
int array[50][50] = {1, 0, 1, 1, 1, 0, 0,
0, 1, 1, 0, 0, 0, 1,
0, 0, etc...}

I've never seen a tutorial explaining arrays used in that way, but I think it might be useful for something I'm doing. So, could someone explain me how it works please? [edited by - Ragadast on June 2, 2002 2:54:00 PM]

Share on other sites
Nuh-uh. Not with a 2D array. To do that you''d have to say
int array[50][50] =
{ { 0, 0, 0, 0, 0, ...}, {0, 0, 0, 0, 0, 0, ...}, ...};

In other words, each row is an array, a subset of the matrix. You have to set each element in each row as shown above if you want to do that.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//

[if you have a link proposal, email me.]

Share on other sites
Ok. But what''s the mean of
{0, 1, 1, 1, 0, 1}?

Is it a number? Each line of numbers correspond to one of the elements of the array, right?

Share on other sites
Each number corrosponds to a single element of the array (a single memory location); Each line is a ROW in the array. However, each row is also an array in and of itself. That''s why the initialization is expressed that way.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//

[if you have a link proposal, email me.]

Share on other sites
If you have this array:

int array [3][3] = { {2, 4, 6}, {8, 10, 12}, {14, 16, 18} };

then if you want to assign the number 12 in this array to another variable, you would write this:

int some_value;

some_value = array[2][3];

...or if you want to assign the number 16 to another variable you write this:

int another value;

another_value = array [3][2];

did this help?

Share on other sites
If you have this array:

int array [3][3] = { {2, 4, 6}, {8, 10, 12}, {14, 16, 18} };

then if you want to assign the number 12 in this array to another variable, you would write this:

int some_value;

some_value = array[2][3];

...or if you want to assign the number 16 to another variable you write this:

int another value;

another_value = array [3][2];

did this help?

Share on other sites
Thanks a lot, i got it

Share on other sites
wait a sec, isn''t the first element of an array supposed to be labled 0?

so in this case, if you want to assign the number 12 in the array to another variable, wouldn''t you write this:

int some_value;

some_value = array[1][2];

correct me if i''m wrong...still a bit sketchy on arrays.

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 10
• 9
• 9
• 11
• Forum Statistics

• Total Topics
633694
• Total Posts
3013372
×