Name:
Class:
Date:
Page 1
Indicate whether the statement is true or false.
1. The first variable in a one-dimensional array is assigned a subscript of 1.
a.
True
b.
False
2. Many C++ compilers initialize char array elements to a space, string array elements to the empty string, and bool array
elements to the keyword true.
a.
True
b.
False
3. Just like scalar variables, arrays in C++ are passed automatically by value.
a.
True
b.
False
4. Another name for an array variable is an element.
a.
True
b.
False
5. A bubble sort works great for sorting an array with a large number of elements.
a.
True
b.
False
6. A subscript in an array is always an integer.
a.
True
b.
False
7. Just like scalar variables, you need to code the address-of operator before the name of an array’s formal parameter in
the function header when passing the array by reference.
a.
True
b.
False
8. A scalar variable is one that is unrelated to any other variable in memory.
a.
True
b.
False
9. When you group together related variables that have different data types, the group is referred to as an array of
variables or, more simply, an array.
a.
True
b.
False
10. An entire array cannot be passed to a function, it must be passed one element at a time.
a.
True
b.
False
11. With parallel arrays, both arrays must contain elements of the same data type.
Name:
Class:
Date:
Page 2
a.
True
b.
False
Indicate the answer choice that best completes the statement or answers the question.
12. When declaring and initializing an array, which of the following best describes the status of the initialValues section?
a.
required
b.
optional
c.
contained within quotes
d.
contained within square brackets
13. Assigning initial values to an array is often referred to as doing what to the array?
a.
creating
b.
declaring
c.
populating
d.
instantiating
14. Which of the following statements will store the user’s entry into the second element of the numbers array?
a.
numbers[1] = 0;
b.
numbers[2] = 0;
c.
cin >> numbers[1];
d.
cin >> numbers[2];
15. Which of the following is a likely while statement used in the outer loop of a bubble sort of an array called distances?
a.
while(distances[sub] > distances[sub -1])
b.
while(sub < maxSub)
c.
while (swap == true)
d.
while(temp == 0)
16. How are arrays stored in memory locations?
a.
randomly
b.
in parallel
c.
contiguously
d.
vertically
17. When passing an array to a function, which of the following should come after the formal parameter name of the array
in the function header to indicate it is an array?
a.
&
b.
[ ]
c.
{ }
d.
||
18. What subscript should be used to access the fourth element in a one-dimensional array?
a.
2
b.
3
c.
4
d.
5
19. Which statement correctly declares and populates a one-dimensional array?
a.
char myArray[4] = {’10’, ‘100’, ‘1000’, ‘10000’};
b.
char myArray{4} = [’10’, ‘100’, ‘1000′, ‘10000’];
c.
int myArray[4] = {10, 100, 1000, 10000};
d.
int myArray{4} = [10, 100, 1000, 10000];
20. What is the data type of a subscript used in an array?
a.
integer
b.
real value
c.
character
d.
string
21. Before using an array in a program, what first must be done to the array?
a.
declare it
b.
load it
c.
populate it
d.
instantiate it
Name:
Class:
Date:
Page 3
22. After the first pass in a typical ascending value bubble sort, what best describes the last element in an array?
a.
the lowest value
b.
the highest value
c.
the midrange value
d.
second highest value
23. What is a group of related variables that have the same data type?
a.
a scalar group
b.
a simple group
c.
an array
d.
a pointer
24. What value is a subscript assigned to access the first element in a one-dimensional array?
a.
0
b.
1
c.
-1
d.
NULL
25. Which of the following statements declares a one-dimensional array containing two integer values?
a.
int numbers[3] = {1, 2, 3};
b.
char letters[2] = {‘a’, ‘b’};
c.
int characters[2] = {45, 87};
d.
int ages[6] = {0};
26. Given the following code, which statement displays each element of the array, one line at a time?
char myArray[4] = {‘a’, ‘b’, ‘c’, ‘d’};
for (int i = 0; i < 4; i += 1)
—- code goes here —-
a.
cout >> myArray[i] >> endl;
b.
cout << myArray[i] << endl;
c.
cout << myArray[4] << endl;
d.
cout >> myArray >> endl;
27. What are the most commonly used arrays in business applications?
a.
one-dimensional arrays only
b.
two-dimenstional arrays only
c.
one-dimensional and two dimensional arrays
d.
multi-dimensional arrays (3 or more dimensions)
28. What, if anything, is needed to fix the following code so that the elements of the array are printed, one line at a time?
char myArray[4] = {‘a’, ‘b’, ‘c’, ‘d’};
for (int i = 1; i < 4; i += 1)
cout << myArray[i] << endl;
a.
change the loop comparison to i <= 3
b.
change the array declaration to myArray[3]
c.
nothing needs to be changed
d.
change the initial value of i
29. Which type of sort provides a quick and easy way to sort the items stored in an array, as long as the number of items is
relatively small?
a.
insertion sort
b.
bubble sort
c.
binary sort
d.
position sort
30. With one-dimensional arrays, what indicates the variable’s position within the array?
a.
a pointer
b.
the subscript
c.
a counter
d.
the array initializer
31. How can the code in the following example best be described?
int scoreThreshold[4] = {90, 80, 70, 60};
Name:
Class:
Date:
Page 4
char letterGrade[4] = {‘A’, ‘B’, ‘C’, ‘D’};
a.
multi-value arrays
b.
two-dimensional array
c.
scalar arrays
d.
parallel arrays
32. Each variable within an array is referred to as which of the following?
a.
index
b.
scalar
c.
pointer
d.
element
33. Which of the following is two or more arrays whose elements are related by their corresponding position (subscript) in
the arrays?
a.
scalar array
b.
corresponding array
c.
parallel array
d.
sequential array
34. What characteristic should the values used to populate an array and the array variables have in common?
a.
position
b.
subscript
c.
data type
d.
equivalence
35. Which of the following describes how an array is automatically passed to a function?
a.
by value
b.
by reference
c.
by type
d.
by subscript
36. What is another name for a simple variable?
a.
array variable
b.
scalar variable
c.
pointer variable
d.
address variable
37. What term is defined as arranging data in a specific order?
a.
sorting
b.
instantiating
c.
referencing
d.
invoking
38. Given the array declaration below, write the assignment statement to place the number 5 into the fifth array element.
int numbers[5] = {0};
39. Given the array declaration below, write a for loop to print the elements of the array on the screen one per line. Use
num as your loop variable for the for loop.
int numbers[5] = {1, 2, 3, 4, 5};
__________________________
40. Given the array declaration below and user prompt, write the statement to place the number 1 into the first array
element using the extraction operator.
int numbers[5] = {0};
cout << “Enter the first number: “;
Name:
Class:
Date:
Page 5
__________________________
41. Given the array declaration below, what is stored in numbers[2] ?
int numbers[5] = {1, 2, 3, 4, 5};
42. What happens when an array declaration statement does not provide an initial value for each of the elements in a
numeric array? In other words, the initialValues section of the declaration is not coded.
43. Given the array declaration below, what is stored in numbers[2] ?
int numbers[5] = {0};
44. How can the computer locate the remaining array elements if only the address of the first array element is passed to a
function?
45. Why are arrays passed automatically by reference, unlike scalar variables?
46. Declare a one-dimensional array called letters to contain the first five lowercase letters of the alphabet.
47. Under what circumstances is the best time to use a bubble sort involving an array? Very briefly, describe how does a
bubble sort works.
Name:
Class:
Date:
Page 6
Name:
Class:
Date:
Name:
Class:
Date:
Page 8