|
|
View previous topic :: View next topic |
Author |
Message |
chingB
Joined: 29 Dec 2003 Posts: 81
|
storing integer in an array |
Posted: Mon Jan 12, 2004 4:11 am |
|
|
Hi,
I need help on how to store an integer in an array? Say I have the following:
numb1 = 16
numb2 = 25
numb3 = 20
numb4 = 4
Any code snippet to store these numbers to an array? say...
array1[0] = 16
array1[1] = 25
array1[2] = 20
array1[3] = 4
I'll appreciate any help.
Thank u. |
|
|
Ttelmah Guest
|
Re: storing integer in an array |
Posted: Mon Jan 12, 2004 5:04 am |
|
|
chingB wrote: | Hi,
I need help on how to store an integer in an array? Say I have the following:
numb1 = 16
numb2 = 25
numb3 = 20
numb4 = 4
Any code snippet to store these numbers to an array? say...
array1[0] = 16
array1[1] = 25
array1[2] = 20
array1[3] = 4
I'll appreciate any help.
Thank u. |
What you post will work.
Obviously, you need 'array1' declared, and large enough to hold the values. So:
int array1[4];
Remember all your lines need the ';' terminator.
You could also declare the array to be 'pre-filled' with the numbers, as:
int array1[] = {16,25,20,4};
The compiler will automatically make the array large enough to hold the number of values declared.
These values will be stored into the array, when the code starts, but the numbers can then be changed as needed.
This differs from a 'constant' array, such as:
const int array1[] = {16,25,20,4};
Which will contain the same numbers, but they then cannot be changed.
Best Wishes |
|
|
chingB
Joined: 29 Dec 2003 Posts: 81
|
Re: storing integer in an array |
Posted: Mon Jan 12, 2004 7:49 am |
|
|
chingB wrote: | Hi,
I need help on how to store an integer in an array? Say I have the following:
numb1 = 16
numb2 = 25
numb3 = 20
numb4 = 4
Any code snippet to store these numbers to an array? say...
array1[0] = 16
array1[1] = 25
array1[2] = 20
array1[3] = 4
I'll appreciate any help.
Thank u. |
what if numb1, numb2, numb3, & numb4 are integer values that varies depending on the program... say a counter that changes depending on a condition... wen a condition are met then the current integer value of numb1, numb2, numb3, & numb3 should be stored in an array.
Can u comments on this.
Thnx |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: storing integer in an array |
Posted: Mon Jan 12, 2004 8:47 am |
|
|
chingB wrote: |
what if numb1, numb2, numb3, & numb4 are integer values that varies depending on the program... say a counter that changes depending on a condition... wen a condition are met then the current integer value of numb1, numb2, numb3, & numb3 should be stored in an array.
Can u comments on this.
Thnx |
You can change the array of interers from 8 bit to 16 bit but only at compile time.
Int8 Buffer[8];
or
Int16 Buffer[8]; |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 12, 2004 9:08 am |
|
|
Code: |
if (condition)
{
array1[0] = numb1;
array1[1] = numb2;
array1[2] = numb3;
array1[3] = numb4;
}
|
|
|
|
|
|
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
|