Professional Documents
Culture Documents
3) To access an array element, use the array name and the element's ________.
A) data type
B) subscript
C) name
D) value
E) None of these
Answer: B
1
Copyright © 2015 Pearson Education, Inc.
5) The statement:
6) 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) None of these
Answer: C
7) The name of an array stores the ________ of the first array element.
A) memory address
B) value
C) element number
D) data type
E) None of these
Answer: A
2
Copyright © 2015 Pearson Education, Inc.
10) If you leave out the size declarator in an array definition:
A) you must furnish an initialization list
B) you are not required to initialize the array elements
C) all array elements default to zero values
D) your array will contain no elements
Answer: A
13) When writing functions that accept multi-dimensional arrays as arguments, ________ must be
explicitly stated in the parameter list.
A) all dimensions
B) all but the first dimension
C) the size declarator of the first dimension
D) all element values
E) None of these
Answer: B
14) An array can store a group of values, but the values must be:
A) the same data type
B) each of a different data type
C) constants
D) integers
E) None of these
Answer: A
15) An array's size declarator must be a ________ with a value greater than ________.
A) number, one
B) number, zero
C) constant integer expression, zero
D) variable, -1
E) None of these
Answer: C
3
Copyright © 2015 Pearson Education, Inc.
16) Subscript numbering in C++________.
A) can be set at runtime
B) can begin with a programmer-defined value
C) varies from program to program
D) begins with zero
E) None of these
Answer: D
18) Given the following declaration, where is the value 77 stored in the scores array?
A) scores[0]
B) scores[1]
C) scores[2]
D) scores[4]
Answer: C
20) The range-based for loop, in C++ 11, is designed to work with a built-in variable known as the
________.
A) counter variable
B) i variable
C) iterator
D) range variable
E) None of these
Answer: D
4
Copyright © 2015 Pearson Education, Inc.
21) To assign the contents of one array to another, you must use ________.
A) the assignment operator with the array names
B) the equality operator with the array names
C) a loop to assign the elements of one array to the other array
D) Any of these
E) None of these
Answer: C
22) To pass an array as an argument to a function, pass the ________ of the array.
A) contents
B) size, expressed as an integer
C) name
D) value of the first element
E) None of these
Answer: C
25) A(n) ________ can be used to specify the starting values of an array.
A) initialization list
B) array name
C) subscript
D) element
E) None of these
Answer: A
26) The ________ is automatically appended to a character array when it is initialized with a string
constant.
A) array name
B) number of elements
C) value of the first element
D) null terminator
E) None of these
Answer: D
5
Copyright © 2015 Pearson Education, Inc.
27) An array with no elements is ________.
A) legal in C++
B) illegal in C++
C) automatically furnished one element, with a value of zero
D) automatically furnished one value—the null terminator
E) None of these
Answer: B
28) An array of string objects that will hold 5 names would be declared using which statement?
A) string names[5];
B) string names(5);
C) string names5;
D) String[5] names;
E) None of these will work.
Answer: A
29) It is ________ to pass an argument to a function that contains an individual array element, such as
numbers[3].
A) illegal in C++
B) legal in C++
C) not recommended by the ANSI committee
D) not good programming practice
E) None of these
Answer: B
30) What is the last legal subscript that can be used with the following array?
int values[5];
A) 0
B) 5
C) 6
D) 4
Answer: D
int bugs[1000];
A) 1000
B) 999
C) 1001
D) Cannot tell from the code
Answer: A
6
Copyright © 2015 Pearson Education, Inc.
32) What will the following code display?
A) 55
B) 66
C) 101
D) 87
Answer: A
A) 99
87
66
55
101
B) 87
66
55
101
C) 87
66
55
A) 87
B) 0
C) garbage
D) This code will not compile
Answer: B
7
Copyright © 2015 Pearson Education, Inc.
35) What will the following code do?
36) Which statement correctly defines a vector object for holding integers?
A) vector v<int>;
B) int vector v;
C) int<vector> v;
D) vector<int> v;
Answer: D
37) Which statement correctly uses C++ 11 to initialize a vector of ints named n with the values 10 and
20?
A) vector n<int>(10, 20);
B) vector<int> n = {10, 20};
C) vector<int> n { 10, 20 };
D) int vector n ({10}, {20});
Answer: C
vector<int> v(10);
A) It creates a vector object and initializes all of its elements to the value 10.
B) It creates a vector object with a starting size of 10.
C) It creates a vector object and initializes the first element with the value 10.
D) It creates a vector object that can store only values of 10 or less.
Answer: B
8
Copyright © 2015 Pearson Education, Inc.
39) What will the following C++ 11 code display?
vector<int> numbers { 3, 5 };
A) 5
5
5
B) 3
3
3
3
3
C) 3
5
A) It creates a vector object and initializes all the first two elements with the values 10 and 2.
B) It creates a vector object with a starting size of 2 and the first element initialized with the value 10.
C) It creates a vector object with a starting size of 10 and the first element initialized with the value 2.
D) It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.
Answer: D
9
Copyright © 2015 Pearson Education, Inc.
43) This vector function removes an item from a vector.
A) remove_item
B) delete_item
C) erase
D) pop_back
Answer: D
44) This vector function returns true if the vector has no elements.
A) has_no_elements
B) null_size
C) empty
D) is_empty
Answer: C
1) True/False: The amount of memory used by an array depends upon the array's data type and the
number of elements in the array.
Answer: TRUE
double money[25.00];
4) True/False: Assume array1 and array2 are the names of arrays. To assign the contents of array2
to array1, you would use the following statement.
array1 = array2;
Answer: FALSE
5) True/False: When you pass an array as an argument to a function, the function can modify the
contents of the array.
Answer: TRUE
7) True/False: If you attempt to store data past an array's boundaries, it is guaranteed that the compiler
will issue an error.
Answer: FALSE
10
Copyright © 2015 Pearson Education, Inc.
8) True/False: An individual array element can be processed like any other type of C++ variable.
Answer: TRUE
9) True/False: In C++ 11, you cannot use a range-based for loop to modify the contents of an array
unless you declare the range variable as a reference.
Answer: TRUE
10) True/False: In C++ 11, the range-based for loop is best used in situations where you need the
element subscript for some purpose.
Answer: FALSE
11) True/False: Although two-dimensional arrays are a novel idea, there is no known way to pass one to
a function.
Answer: FALSE
12) True/False: Each individual element of an array can be accessed by the array name and an element
number, called a subscript.
Answer: TRUE
13) True/False: If an array is partially initialized, the uninitialized elements will be set to zero.
Answer: TRUE
14) True/False: A vector object automatically expands in size to accommodate the items stored in it.
Answer: TRUE
11
Copyright © 2015 Pearson Education, Inc.