Week 11 Part 1 Flashcards

1
Q
  • What is an array?
A

o A collection of values having the same data-type stored in the computers memory in a linear, contiguous manner

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

o Real life examples that can be represented as Arrays

A

 Alphabet = index system
 Prices of each item for sale in a store
 Amount of gasoline to refuel a car each month

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

o What would a declared array called prices (num) look like with an element size of 3

A

num[] prices = new num[3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

o What are the 3 parts of an array declaration?

A

 Data type, variable name, size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

o By convention arrays have ______ names

A

 plural

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

o Each storage location in an array is referred to as an

A

 Element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

o Each element in an array is accessed using a

A

 Subscript, also called an index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“Populating an array” means

A

 Initializing the elements with data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

o The lowest index for an array is _, the max index is the array size minus _

A

 0, minus 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

o Meaning: Array lower bound and upper bound

A

 Lowest index value [0], highest index value [size-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

o Using an index value that is outside of the array bounds will cause problems, such as (2 cases)

A

 Best case - Run time error and crash
 Worst case - Corrupts memory that is not part of your program, causing other programs/OS to crash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

o Java arrays enforce _____ ______, with a run-time exception causing a crash

A

 Array bounds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

o Why is it important to enforce array bounds in programming?

A

 Can be used as a security exploit by hackers, to corrupt memory and run viruses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

o Memory in computers is organized a sequence of _ ____ blocks of _ ___ each

A

 1 byte, 8 bits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

o Each byte in the computer has a unique ______ _______

A

 Memory address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

o Arrays and Memory: size of array’s elements is determined by the arrays

A

 Data type.

17
Q

o Arrays and Memory: Integers in Java occupy 4 bytes of memory. If it’s an integer array, each element will occupy

A

 4 bytes of memory, or 32 bits

18
Q

o Arrays and Memory: Each element of an array is placed ___________ after the other, in a ___________ manner

A

 Immediately, contiguous

19
Q

o How many bytes of memory would this occupy? Int number [4]

A

 16 bytes, 128 bits (4x4bytes), (4x32bits)

20
Q

o In order to find an array in memory, the system uses

A

 The subscript, datatype, and name to perform a calculation and jump to the correct memory location

21
Q

o Explain these
1. int value = numbers[0]
2. numbers[0] = 33

A

 1. Read from a single array element, 2. Write to a single array element

22
Q

o Num numbers[5] = 3.3, 4.4, 5.5 which index will these elements attach to?

A

 Leftmost will attach to 0, and so on*

23
Q

o T/F – Each element in an array diagram is represented by a single box, regardless of the number of bytes

A

True

24
Q

o An Array is a ____ of data items in ___________ memory locations

A

group, contiguous