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.
The discussion revolves around the purpose and usefulness of arrays in programming, exploring their role in storing multiple items, facilitating data manipulation, and comparing them to other data structures. The conversation includes examples and explanations of how arrays can simplify coding tasks.
Participants generally agree on the usefulness of arrays for storing and manipulating data, but there is no consensus on all aspects of their applications or comparisons with other data structures.
Some participants express difficulty in grasping the concept of arrays' usefulness, indicating a potential gap in understanding that may depend on prior knowledge of programming concepts.
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.