CS110 Practice Quiz 9
Arrays
Choose the best alternative:
An
array
consists of a collection of memory cells and is used to store data elements.
True
False
Each data element in an
array
can be accessed by an index.
True
False
A single
array
can store data elements of different data classes (int's, double's, char's, etc.)
True
False
An example of a correct array definition is
char [] myArray = new char[6];
True
False
A example of an incorrect array definition is
int myArray = new int [5];
True
False
The array below can be indexed by 0, 1, 2, 3, 4, 5.
True
False
int [] arr = new int [ 5 ];
All elements of the array below are initialized to 0.
True
False
int [] arr1 = new int [5];
Given the definition below,
arr [3] =
int [] arr = {1 ,2, 3, 4, 5};
What is the index of the last element of the array below?
int [] hold = new int [55] ;
What is the
index
of the first element of the array below?
int [] temp = {2, 7, 4, 4};
Suppose that the index of the last element in an array is [25]. How many elements will the array store?
Questions 15 - 18 refer to the following code segment
int [] arr = new int [4];
for (int i = 0; i < 4; i++)
if ( i % 2 == 0)
arr[ i ] = 2 * i;
else
arr[ i ] = i;
What value is assigned to arr[ 0 ]?
What value is assigned to arr[ 1 ]?
What value is assigned to arr[ 2 ]?
What value is assigned to arr[ 3 ]?
Answers
True
True
False
True
False
False. The index 5 is out of bounds.
True. NOTE: This is usually the case.
4
54
0
26
0
1
4
3