Chapter 46 - Arrays

Slide 1: Describe a good reason to use arrays.

Slide 2: What is an array?
What is a cell?
What is an index?


What is another name for an index?

Which thing can change in an array: the number of cells or the elements?


What is in data[7]? ______

Show how the array changes after this line of code:

data[3] = 99 ; 

What is the value of the arithmetic expression:

data[2] + data[6]? ________

On your own: what is the value of data[4]+data[8]? _______
A tricky one: Make your best guess: what is data[data[6]]? __________
Show what happens in the array as a result of executing the statement:

data[0] = data[6] + 8;

Is an array an object?________

This is different than the example in the chapter:

Given this code:
double[] data = new double[5];
  1. What is the length of the array data?
  2. What are the indexes of data?

Bounds Checking:

  1. Can an index be negative? ____
  2. Can an index have a decimal part like 2.75? ______
  3. Can an index be 0? _______
  4. What is the error that happens if you try to reference an index that doesn't exist? ______________________________

slide 6 arrays

Array Initialization

Each cell of a numeric array is initialized to _____________. Each cell of an array of object references is initialized to _______________

ch 46 question 7. question 7