realism877
- 80
- 0
I know what an array is and what it does. I'm just having a hard time getting the concpet on how it is useful.
realism877 said:I know what an array is and what it does. I'm just having a hard time getting the concpet on how it is useful.
int arrayLength = 30;
int myArray[arrayLength ]; // an array with 30 "slots", pretend we already put the data in
int total = 0;
for(int i = 0; i < arrayLength; i++)
{
total = total + myArray[i];
}
average = total / arrayLength;
int height1, height2, height3, height4, height5, height6 ... height30; // 30 variables!
total = height1 + height2 + height3 + height4 ... + height 30; // !
average = total / 30;
Using an array, you can store multiple values of the same time, using essentially a single name. The individual items in the array can be distinguished by an index.realism877 said:I know what an array is and what it does. I'm just having a hard time getting the concpet on how it is useful.
Assuming that we're talking about programming languages that store strings as arrays of characters. That would include C, C++, and several other languages.Jaynte said:A text string is also a good example.
array[0] == 'A'Jaynte said:The above text i just wrote is an array with characters where array[0] = A, array[1] = "space", array[2] = t. and so on.