Storing multiple values in an array
When you need to store multiple values of the same type, you can declare an array. For example, you may do this when you need to store four names in a string
array.
Working with single-dimensional arrays
The code that you will write next will allocate memory for an array for storing four string
values. It will then store string
values at index positions 0 to 3 (arrays usually have a lower bound of zero, so the index of the last item is one less than the length of the array).
We could visualize the array like this:
0 |
1 |
2 |
3 |
Kate |
Jack |
Rebecca |
Tom |
Table 3.1: Visualization of an array of four string values
...