Week 11 Part 1 Flashcards
- What is an array?
o A collection of values having the same data-type stored in the computers memory in a linear, contiguous manner
o Real life examples that can be represented as Arrays
Alphabet = index system
Prices of each item for sale in a store
Amount of gasoline to refuel a car each month
o What would a declared array called prices (num) look like with an element size of 3
num[] prices = new num[3]
o What are the 3 parts of an array declaration?
Data type, variable name, size
o By convention arrays have ______ names
plural
o Each storage location in an array is referred to as an
Element
o Each element in an array is accessed using a
Subscript, also called an index
“Populating an array” means
Initializing the elements with data
o The lowest index for an array is _, the max index is the array size minus _
0, minus 1
o Meaning: Array lower bound and upper bound
Lowest index value [0], highest index value [size-1]
o Using an index value that is outside of the array bounds will cause problems, such as (2 cases)
Best case - Run time error and crash
Worst case - Corrupts memory that is not part of your program, causing other programs/OS to crash
o Java arrays enforce _____ ______, with a run-time exception causing a crash
Array bounds
o Why is it important to enforce array bounds in programming?
Can be used as a security exploit by hackers, to corrupt memory and run viruses
o Memory in computers is organized a sequence of _ ____ blocks of _ ___ each
1 byte, 8 bits
o Each byte in the computer has a unique ______ _______
Memory address