Chapter 8 Flashcards

Arrays and Vectors

1
Q

Unlike regular variables, arrays can hold multiple …

A

Values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True/False: The amount of memory used by an array depends solely on the number of elements the array can hold.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

To access an array element, use the array name and the element’s …

A

Subscript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True/False: 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;

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The statement
int grades[ ] = {100, 90, 99, 80};

A

Implicit array sizing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

(D)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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 sofo array 1 into array 2.
B) cout &laquo_space;array 2 // Output the elements stored in array 2.
C) array 2 = 5; // Place a 5 in each element of array2.
D) None of the above
E) A and B, but not C

A

(D)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

By using the same [Blank] you can build relationships between data stored in two or more arrays.

A

Subscript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

To step through a one-dimensional array, accessing the elements one by one, it would be most appropriate to use [Blank] loop.

A

A for loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

True/False: Arrays can be passed to functions, but individually array elements cannot be.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When an array is passed to a function, it is actually [Blank] the array that is passed.

A

the starting memory address of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

True/False: When you pass an array as an argument to a function, the function can modify the contents of the array.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A two-dimensional array can be viewed as …

A

A table with rows and columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The elements of an array can be
A) strings
B) Structures
C) Objects
D) Any of the above
E) None of the Above

A

(D)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True/False: An element of a two-dimensional array is referenced by the array name and two subscripts, first the element tow number and then the element column number.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The following statement
for(int val : myArray)
cout &laquo_space;val &laquo_space;” “;
is an example of a(n) …

A

range-based for loop

17
Q

What des the following statement do?
typedef int oneDArray[20];

A

It makes oneDArray an alias for a data type that holds 20 integers.

18
Q

True/False: When you create a vector, it is unnecessary to specify how many elements will hold because it will expand in size as you add new values to it.

A

True

19
Q

True/False: The range-based for loop may be used with arrays, but not with vectors.

A

False

20
Q

True/False: 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};

A

False