Lecture 7 Flashcards
Array
Group of variables with the same name of the same type. Each number has a unique way of identifying it.
Declaring an array
Type name[size];
Or
Type name[] = {number, number, … }
How arrays store data
Declaring an array sets aside as many “boxes” as the size of the array. Each element has it’s own box. Each box is referred to with a number, starting at 0, called an index.
Element
Individual value in an array
Index
Number referring to an element
What is considered a variable in an array
The entire array is considered the variable
Sub
How to refer to an individual element. Array name followed by the index for the element: e.g. X sub 3
Indexing an array
Accessing a single element in an array by using it’s index
Tips for initializing array size
Set it larger than expected if size is unknown, but not so large too much memory is used.
Initializing an array
Type name[size] = {number, …}
Or
Type name[] = {number, …}
^ will initalize size to number of elements
Tips for initializing an array
Set unknown elements to 0
Parallel arrays
Two or more arrays who’s elements at the same index are related.
Multidimensional array
An array with more than one set of numbers
How to initalize the size of a multidimensional array
Type name[size][size];
Can add more than one size by adding another set of square brackets with the size.
How to loop through values
Nested loops