Up to this point we have been using singular data types, such as
int i, j, k;
float x, y, z;
double u, v, w;
Often situations arise in which it is more natural to store a collection of values together in a single variable.
We will first focus on storing integers in an array. For example, we may wish to store all students’ grades on an exam or the coordinates for an object or the values of a function at regular intervals, etc.
An array (think of a collection of data items of the same type) is just what we need to accomplish this efficiently.
If you cannot see this codecast, please click here.
Check Your UnderstandingCheck Your Understanding
1.
How much space is reserved with the following declaration:
int numbers[10];
space for 10 integers
Correct
space for 1 integer
Not quite. Try again!
space for 9 integers
Not quite. Try again!
space for 11 integers
Not quite. Try again!
space for 12 integers
Not quite. Try again!
Now that we know how to create these arrays, how do we actually use them?
If you cannot see this codecast, please click here.