Name:
Class:
Date:
Page 1
Indicate whether the statement is true or false.
1. A one-dimensional array resembles a table in that the array elements are in rows and columns.
a.
True
b.
False
2. When specifying an array element in a two-dimensional array, the column subscript comes before the row subscript.
a.
True
b.
False
3. Before you can use a two-dimensional array in a program, you must initialize it.
a.
True
b.
False
4. You refer to each element in a two-dimensional array by the array’s name and the element’s row and column
subscripts.
a.
True
b.
False
5. The extraction operator can be used to store data in an element in a two-dimensional array.
a.
True
b.
False
6. An array is a group of related variables (elements) that have the same data type.
a.
True
b.
False
7. Like one-dimensional arrays, two-dimensional arrays are passed automatically by value.
a.
True
b.
False
8. Only one loop is needed to access each element in a two-dimensional array.
a.
True
b.
False
9. When declaring a two-dimensional array the statement begins with the array name.
a.
True
b.
False
10. Elements located in the first row in a two-dimensional array are assigned a row subscript of 1.
a.
True
b.
False
Indicate the answer choice that best completes the statement or answers the question.
11. Which of the following would you use to reference the variable located in the first row, first column of the scores two-
Name:
Class:
Date:
Page 2
dimensional array?
a.
scores[0][0]
b.
scores[1][1]
c.
scores{0, 0}
d.
scores[1,1]
12. Given the following array declaration, what is the value stored in the scores[0][0] element?
int scores[5][5] = {5};
a.
0
b.
5
c.
10
d.
25
13. Variables located in the first row in a two-dimensional array are assigned a row subscript of which of the following?
a.
0
b.
1
c.
-1
d.
NULL
14. Given the following array declaration, what is the value stored in the scores[1][2] element?
int scores[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
a.
2
b.
5
c.
6
d.
4
15. How many elements will a two-dimensional array with 4 rows and 5 columns contain?
a.
9
b.
12
c.
18
d.
20
16. What operator can be used to store data in an element in a two-dimensional array?
a.
insertion
b.
extraction
c.
ternary
d.
increment
17. In a two-dimensional array, what is used to specify each element’s row and column positions in the array?
a.
orders
b.
variables
c.
subscripts
d.
indexes
18. Which of the following is the correct inner for loop statement if you want to access each column in the ith row of the
array declared below?
int myArray[4][3];
for (i = 0; i < 4; i += 1)
a.
for (j=1; j <= 3; j +=1) z = myArray[i][j];
b.
for (j=0; j < 3; j += 1) z = myArray[i][j];
c.
for (j=0; j < 3; j +=1) z = myArray[j][i];
d.
for (j=1; j <= 3; j +=1) z = myArray[j][i];
19. When you don’t provide an initial value for each of the elements in an int array, many C++ compilers initialize the
uninitialized elements to what integer?
a.
1
b.
-1
c.
0
d.
“”
20. Which of the following would you use to reference the variable located in the second row, second column of the
Name:
Class:
Date:
Page 3
scores two-dimensional array?
a.
scores[0][0]
b.
scores[1][1]
c.
scores{1, 1}
d.
scores[2,2]
21. Which of the following statements will declare a two-dimensional array called scores to be of the int data type and
contain 3 rows and 4 columns, while also initializing all elements to 0?
a.
int scores [4][3] = 0;
b.
int scores [3][4] = 0;
c.
int scores[3][4] = {0};
d.
int scores[0] = {4, 3};
22. Which of the following is the correct statement to access the 15th element of the declared array?
int myArray[6][5];
a.
z = myArray[2][4];
b.
z = myArray[4][2];
c.
z = myArray[3][5];
d.
z = myArray[5][3];
23. Given the following array declaration, what is the value stored in the scores[2][2] element?
int scores[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
a.
8
b.
5
c.
6
d.
9
24. What value should you assign the subscript to access the element located in the third column in a two-dimensional
array?
a.
3
b.
1
c.
-3
d.
2
25. In the following statement, what does the [4] represent?
studentGrades[4] [2] = ‘B’;
a.
4th element of the array
b.
row subscript
c.
column subscript
d.
8th element of the array
26. Which of the following statements will declare a two-dimensional array called scores to be of the int data type and
contain 2 columns and 3 rows, while also initializing all elements to 0?
a.
int scores [1][2] = {0};
b.
int scores [2][3] = {0};
c.
int scores[3][2] = {0};
d.
int scores[0] = {2, 3};
27. Which of the following would be used to refer to the element located in the second row, third column of a two-
dimensional array named orders?
a.
orders [2] [3]
b.
orders [1,2]
c.
orders [2, 3]
d.
orders [1] [2]
28. What happens if an invalid subscript is used to access a two-dimensional array element?
a.
error message and program ends
b.
program continues
c.
type conversion
d.
the system will will prompt the user
Name:
Class:
Date:
Page 4
29. Given the following array declaration, what is the value stored in the scores[2][3] element?
int scores[5][5] = {5};
a.
0
b.
5
c.
cannot be determined
d.
25
30. Given the following array declaration, what is the value stored in the scores[1][1] element?
int scores[5][5] = {5};
a.
0
b.
5
c.
10
d.
25
31. How many loops are necessary to access the contents of a two-dimensional array efficiently?
a.
0
b.
1
c.
2
d.
more than 2
32. Given the following array declaration, what is the value stored in the scores[2][3] element?
int scores[5][5] = {0};
a.
0
b.
5
c.
cannot be determined
d.
25
33. What type of array resembles a table with rows and columns?
a.
one-dimensional
b.
two-dimensional
c.
scalar
d.
integer
34. Given the following array declaration, what is the value stored in the scores[1][1] element?
int scores[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
a.
1
b.
4
c.
7
d.
5
35. How many loops are necessary to access the contents of a one-dimensional array efficiently?
a.
0
b.
1
c.
2
d.
more than 2
36. Given the following array declaration, what is the value stored in the scores[1][1] element?
int scores[3][3] = { {1, 2, 3} };
a.
0
b.
1
c.
2
d.
3
37. Given the declaration below, code the statement to assign the element in the last row and last column a value of 99.
Name:
Class:
Date:
Page 5
int scores[3][2] = {0};
38. Write the statement to do the following:
– create a two-dimensional array called orders
each element will be of the int data type
– there will be 2 rows and 3 columns
each element will be initialized to 0
39. If a two-dimensional array declard to be of the int data type was very large and you wished to initialize all of the
elements of the array to something other than 0 (for example, 99), it would be quite exhausting to code all of the initial
values. Write a nested loop using two for loops to initialize all of the elements in the array below to 99. Use row and col
for your loop variables.
int scores[100][100] = {0};
40. Write the statement to do the following:
– create a two-dimensional array called letters
each element will be of the char data type
– there will be 2 rows and 2 columns
each element will be initialized to ‘x’
41. In order to access each element efficiently in a two-dimensional array, you would need a nested loop structure. What
types of loops would you use and why?
42. Given the declaration below, code the statement to assign the element in the first row and first column a value of 99.
int scores[3][2] = {0};
43. Given the declaration below, code the statement to assign the element in the last row and last column a value of 99.
int scores[6][7] = {0};
44. Write the statement to do the following:
– create a two-dimensional array called scores
each element will be of the int data type
– there will be 3 rows and 2 columns
each element will be initialized to 100
45. Given the declarations below, write a nested loop using two for loops to sum all of the elements in the array below.
Use row and col for your loop variables.
int scores[3][3] = { {92, 87, 91}, {88, 72, 93}, {100, 94, 97} };
int sum = 0;
46. Given the declaration below, code the statement to assign the element in the first row and first column the value
entered by the user through the prompt below.
int scores[3][2] = {0};
cout << “Please enter the first score: “;
_____________________________
Name:
Class:
Date:
Page 6
Name:
Class:
Date:
Page 7
27. d
28. a
31. c
34. d
char letters[2][2] = { {‘x’, ‘x’}, {‘x’, ‘x’} };
Name:
Class:
Date:
Page 8