Deck 8: Arrays
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
Play
Full screen (f)
Deck 8: Arrays
1
When an array is passed to a function, it is actually ________ the array that is passed.
A) the starting memory address of
B) a copy of all the values in
C) the value stored in the first element of
D) the data type and size of
E) the data type and name of
A) the starting memory address of
B) a copy of all the values in
C) the value stored in the first element of
D) the data type and size of
E) the data type and name of
A
2
When you pass an array as an argument to a function, the function can modify the contents of the array.
True
3
The amount of memory used by an array depends solely on the number of elements the array can hold.
False
4
Which of the following statements correctly initialize the value variable?
A) int value = 8;
B) int value{8};
C) int value(8);
D) All of the above.
E) Both A and B, but not C.
A) int value = 8;
B) int value{8};
C) int value(8);
D) All of the above.
E) Both A and B, but not C.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
If a C++ program contains the following array definition
int score[10];
the following statement would store 100 in the first array element:
score[1] = 100;
int score[10];
the following statement would store 100 in the first array element:
score[1] = 100;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
A two-dimensional array can be viewed as
A) two rows of values.
B) two columns of indexes.
C) a table with rows and columns.
D) any of the above.
E) none of the above.
A) two rows of values.
B) two columns of indexes.
C) a table with rows and columns.
D) any of the above.
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following statements will correctly carry out the operation stated in the comment to its right.
A) array 2 = array1 // Copy the elements of array 1 into array 2.
B) cout << array2 // Output the elements stored in array 2.
C) array2 = 5; // Place a 5 in each element of array2.
D) None of the above.
E) A and B, but not C.
A) array 2 = array1 // Copy the elements of array 1 into array 2.
B) cout << array2 // Output the elements stored in array 2.
C) array2 = 5; // Place a 5 in each element of array2.
D) None of the above.
E) A and B, but not C.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
What does the following statement do?
Typedef int oneDArray[20];
A) It creates an array of 20 integers.
B) It makes oneDArray a copy of another 20-integer array.
C) It makes oneDArray an alias for a data type that holds 20 integers.
D) It creates a one-dimensional integer array with all elements initialized to 20.
E) It does none of the above.
Typedef int oneDArray[20];
A) It creates an array of 20 integers.
B) It makes oneDArray a copy of another 20-integer array.
C) It makes oneDArray an alias for a data type that holds 20 integers.
D) It creates a one-dimensional integer array with all elements initialized to 20.
E) It does none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
An element of a two-dimensional array is referenced by the array name and two subscripts, first the element row number and then the element column number.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
Unlike regular variables, arrays can hold multiple
A) data types.
B) named constants.
C) values.
D) variables.
E) operators.
A) data types.
B) named constants.
C) values.
D) variables.
E) operators.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
Arrays can be passed to functions, but individual array elements cannot be.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
The following statement for(int val : myArray)
Cout << val << " ";
Is an example of a(n)
A) regular for loop.
B) range-based for loop.
C) nested for loop.
D) infinite for loop.
E) illegal statement.
Cout << val << " ";
Is an example of a(n)
A) regular for loop.
B) range-based for loop.
C) nested for loop.
D) infinite for loop.
E) illegal statement.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
When you create a vector it is unnecessary to specify how many elements it will hold because it will expand in size as you add new values to it.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
The elements of an array can be
A) strings.
B) structures.
C) objects.
D) any of the above.
E) none of the above.
A) strings.
B) structures.
C) objects.
D) any of the above.
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
By using the same ________ you can build relationships between data stored in two or more arrays.
A) array name
B) data
C) subscript
D) arguments
E) data type
A) array name
B) data
C) subscript
D) arguments
E) data type
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
The statement int grades[ ] = { 100, 90, 99, 80 };
Is an example of
A) default arguments.
B) an illegal array declaration.
C) an illegal array initialization.
D) data encapsulation.
E) implicit array sizing.
Is an example of
A) default arguments.
B) an illegal array declaration.
C) an illegal array initialization.
D) data encapsulation.
E) implicit array sizing.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
If employee is an array of objects with a public member function named setHourlyWage, the following statement correctly calls this method for employee[2].
employee.setHourlyWage[2](20.00);
employee.setHourlyWage[2](20.00);
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
The range-based for loop may be used with arrays, but not with vectors.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
To access an array element, use the array name and the element's
A) name.
B) data type.
C) value.
D) subscript.
E) size declarator.
A) name.
B) data type.
C) value.
D) subscript.
E) size declarator.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
To step through a one-dimensional array, accessing the elements one by one, it would be most appropriate to use ________ loop.
A) an infinite
B) a sentinel controlled loop
C) a for loop
D) a nested loop
E) no
A) an infinite
B) a sentinel controlled loop
C) a for loop
D) a nested loop
E) no
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
If employee is an array of objects with a public member function named setHoursWorked, which of the following statements correctly calls that function for the employee object in array element 5?
A) employee.setHoursWorked[5] = 40;
B) employee[5].setHoursWorked = 40;
C) employee.setHoursWorked[5](40);
D) employee[5].setHoursWorked(40);
E) setHoursWorked(employee[5], 40);
A) employee.setHoursWorked[5] = 40;
B) employee[5].setHoursWorked = 40;
C) employee.setHoursWorked[5](40);
D) employee[5].setHoursWorked(40);
E) setHoursWorked(employee[5], 40);
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
After carrying out the following two statements, sales will have been created as a one-dimensional array that can hold 20 double values.
typedef salesArray double[20];
salesArray sales;
typedef salesArray double[20];
salesArray sales;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
The following two arrays string deptName[3] = {"Manufacturing", "Sales", "Business Office");
Double deptBudget[3] = {200000.0, 60000.0, 50000.0};
Are an example of ________ arrays.
A) two-dimensional
B) paired
C) linked
D) parallel
E) brother
Double deptBudget[3] = {200000.0, 60000.0, 50000.0};
Are an example of ________ arrays.
A) two-dimensional
B) paired
C) linked
D) parallel
E) brother
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
The following array definition is legal because C++ allows arrays to be implicitly sized.
int grades[ ];
int grades[ ];
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
In C++ If you attempt to store more data in an array than it can hold, the compiler will issue an error.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
If the scores array is defined like this: int scores[ ]= {4, 7, 4, 8, 9};
What will the following statement display?
Cout << scores[4];
A) 4
B) 7
C) 8
D) 9
E) the first four scores
What will the following statement display?
Cout << scores[4];
A) 4
B) 7
C) 8
D) 9
E) the first four scores
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
Each individual element of an array can be accessed by the array name and an element number, called a subscript.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
An individual array element can be processed or passed to a function just like a regular C++ variable.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
An array can be returned by a function as well as passed to a function.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
Subscript numbering in C++
A) can be set at run time.
B) can begin with a programmer-defined value.
C) varies from program to program.
D) automatically begins with zero.
E) automatically begins with one.
A) can be set at run time.
B) can begin with a programmer-defined value.
C) varies from program to program.
D) automatically begins with zero.
E) automatically begins with one.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
An array can store multiple values, but the values must be
A) all the same data type.
B) declared at the time the array is created.
C) constants.
D) numeric, not characters or strings.
E) none of the above.
A) all the same data type.
B) declared at the time the array is created.
C) constants.
D) numeric, not characters or strings.
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
The amount of memory used by an array depends upon the array's data type and how many elements it can hold.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
The following statement is a valid C++ array definition.
double money[25.00];
double money[25.00];
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
Elements of vectors can be access by using the vector name and a subscript, similarly to how array elements are accessed.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
Any of the following statements can be used to initialize the integer variable num to 7;
int num = 7;
int num(7);
int num{7};
int num = 7;
int num(7);
int num{7};
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
You can assign the contents of one array to another by using
A) the assignment operator.
B) the equality operator.
C) both array names.
D) A and C together.
E) none of the above.
A) the assignment operator.
B) the equality operator.
C) both array names.
D) A and C together.
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
When an array is passed to a function, it is actually ________ the array that is/are passed.
A) a copy of all the values in
B) the value stored in the first element of
C) the starting memory address of
D) the data type and size of
E) none of the above
A) a copy of all the values in
B) the value stored in the first element of
C) the starting memory address of
D) the data type and size of
E) none of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
The size of an array is the number of elements that have data stored in them.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
To add up all the values in a two-dimensional array it would be best to use
A) one for loop
B) two separate for loops
C) a nested for loop
D) no loop
E) one sentinel controlled loop
A) one for loop
B) two separate for loops
C) a nested for loop
D) no loop
E) one sentinel controlled loop
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
On each iteration of the following range-based for loop for (int element : myArray)
Cout << element << endl;
The variable element holds
A) an array value.
B) an array subscript.
C) an array name.
D) an array location.
E) none of the above.
Cout << element << endl;
The variable element holds
A) an array value.
B) an array subscript.
C) an array name.
D) an array location.
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck