Store data in arrays
Array
A series or list of variables in computer memory
All variables share the same name, and must be the same data type
Each variable has a different subscript [0] [1] [2]
How arrays occupy computer memory
Element: an item in the array
Initialization list: values assigned to array elements in declarations (num prices [3] = 25,
36, 47)
Size of the array: the number of elements it will hold
Subscripts or indexes: position number of an item in an array, subscripts are always a
sequence [0] [1] [2]
Adding data values is called populating the array
Describe how an array can replace nested decisions
The array reduces the number of statements needed
Six count accumulators are redefined as a single array (count [x] where x is between 0 and 5)
Variable as a subscript to the array
Array subscript variable must be:
Numeric with no decimal places
Initialized to 0
Incremented by 1 each time the logic passes through the loop (count = count + 1)
Use constants with arrays
Use constants in several ways
To hold the size of an array
As the array values
As subscripts
Avoid "magic numbers" (unnamed constants)
Declare named numeric constant to be used every time the array is accessed
Make sure any subscript remains less than the constant value
Constants are created automatically in many languages
Sometimes the values stored in arrays should be constants
Example string MONTH [12] = "Jan", "Feb", "Mar", "Apr", "May", ...