Chapter 7 Flashcards

1
Q
  1. The _________ indicates the number of elements, or values, an array can hold.
A

size declarator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. The size declarator must be a(n) _________ with a value greater than _________.
A

integer, 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Each element of an array is accessed and indexed by a number known as a(n) _________.
A

subscript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Subscript numbering in C++ always starts at _________.
A

0

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

The number inside the brackets of an array definition is the _________, but the number
inside an array’s brackets in an assignment statement, or any other statement that
works with the contents of the array, is the _________

A

size declarator, subscript

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

C++ has no array _________ checking, which means you can inadvertently store data
past the end of an arra

A

bounds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Starting values for an array may be specified with a(n) _________ list.
A

initialization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. If an array is partially initialized, the uninitialized elements will be set to _________.
A

0

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

If the size declarator of an array definition is omitted, C++ counts the number of items
in the _________ to determine how large the array should be

A

initialization list

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

By using the same _________ for multiple arrays, you can build relationships between
the data stored in the arrays

A

subscript

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

You cannot use the _________ operator to copy data from one array to another in a
single statement.

A

=

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

Any time the name of an array is used without brackets and a subscript, it is seen as
_________

A

an address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. To pass an array to a function, pass the _________ of the array.
A

address, or name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. A(n) _________ array is like several arrays of the same type put together.
A

multi-dimensional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. It’s best to think of a two-dimensional array as having _________ and _________.
A

rows, columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. To define a two-dimensional array, _________ size declarators are required.
A

two

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

When initializing a two-dimensional array, it helps to enclose each row’s initialization
list in _________.

A

braces

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

When a two-dimensional array is passed to a function the _________ size must be
specified

A

column

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

The ____________________ is a collection of programmer-defined data types and
algorithms that you may use in your programs

A

Standard Template Library (or STL)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q
  1. The two types of containers defined by the STL are ___________ and ______________.
A

sequence and associative

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
  1. The vector data type is a(n) ______________ container.
A

sequence

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

To define a vector in your program, you must #include the ____________ header
file

A

vector

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

To store a value in a vector that does not have a starting size, or that is already full,
use the ________________ member function

A

push_back

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

To determine the number of elements in a vector , use the _____________ member
function

A

size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q
  1. Use the ________________ member function to remove the last element from a vector .
A

pop_back

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q
  1. To completely clear the contents of a vector , use the ___________ member function.
A

clear

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

An array’s size declarator can be either a literal, a named constant, or a
variable

A

f

28
Q

To calculate the amount of memory used by an array, multiply the number
of elements by the number of bytes each element uses

A

t

29
Q

The individual elements of an array are accessed and indexed by unique
numbers.

A

t

30
Q

The first element in an array is accessed by the subscript 1.

A

f

31
Q

The subscript of the last element in a single-dimensional array is one less
than the total number of elements in the array

A

t

32
Q

The contents of an array element cannot be displayed with cout .

A

false

33
Q

Subscript numbers may be stored in variables.

A

true

34
Q

You can write programs that use invalid subscripts for an array.

A

true

35
Q

Arrays cannot be initialized when they are defined. A loop or other means
must be used.

A

false

36
Q

The values in an initialization list are stored in the array in the order they
appear in the list

A

true

37
Q

C++ allows you to partially initialize an array.

A

true

38
Q

If an array is partially initialized, the uninitialized elements will contain
“garbage.

A

false

39
Q

If you leave an element uninitialized, you do not have to leave all the ones
that follow it uninitialized

A

false

40
Q

If you leave out the size declarator of an array definition, you do not have to
include an initialization list

A

false

41
Q

The uninitialized elements of a string array will automatically be set to the
value “0”

A

false

42
Q

You cannot use the assignment operator to copy one array’s contents to
another in a single statement

A

true

43
Q

When an array name is used without brackets and a subscript, it is seen as
the value of the first element in the array.

A

false

44
Q

To pass an array to a function, pass the name of the array.

A

true

45
Q

When defining a parameter variable to hold a single-dimensional array argument,
you do not have to include the size declarator.

A

true

46
Q

When an array is passed to a function, the function has access to the original
array.

A

true

47
Q

A two-dimensional array is like several identical arrays

A

true

48
Q

It’s best to think of two-dimensional arrays as having rows and columns.

A

true

49
Q

The first size declarator (in the declaration of a two-dimensional array)
represents the number of columns. The second size definition represents the
number of rows.

A

false

50
Q

Two-dimensional arrays may be passed to functions, but the row size must
be specified in the definition of the parameter variabl

A

false

51
Q

C++ allows you to create arrays with three or more dimensions

A

true

52
Q

A vector is an associative container

A

false

53
Q

To use a vector , you must include the vector header file.

A

true

54
Q

Vector s can report the number of elements they contain.

A

true

55
Q

You can use the [] operator to insert a value into a vector that has no
elements

A

false

56
Q

If you add a value to a vector that is already full, the vector will automatically
increase its size to accommodate the new value

A

true

57
Q

int size;
double values[size];

A

The size declarator cannot be a variable.

58
Q
  1. int collection[-20];
A

The size declarator cannot be negative.

59
Q
  1. int table[10];
    for (int x = 0; x < 20; x++)
    {
    cout &laquo_space;“Enter the next value: “;
    cin&raquo_space; table[x];
    }The loop will write data past the end of the array.
A

The loop will write data past the end of the array.

60
Q
  1. int numbers[8] = {1, 2, , 4, , 5};
A

The initialization list must be enclosed in braces.

61
Q
  1. float ratings[];
A

For the array to be implicitly sized there must be an initialization list.

62
Q
  1. char greeting[] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’};
    cout &laquo_space;greeting;
A

A null terminator must be specified in the initialization list.

63
Q
  1. int array1[4], array2[4] = {3, 6, 9, 12};
    array1 = array2;
A

The assignment operator cannot be used to assign the contents of one array to
another, in a single statement

64
Q
  1. void showValues(int nums)
    {
    for (int count = 0; count < 8; count++)
    cout &laquo_space;nums[count];
    }
A

The parameter should be declared as int nums[]. Also, the function should
have a parameter to hold the size of the array

65
Q
  1. void showValues(int nums[4][])
    {
    for (rows = 0; rows < 4; rows++)
    for (cols = 0; cols < 5; cols++)
    cout &laquo_space;nums[rows][cols];
    }
A

The parameter must specify the number of columns, not the number of rows.

66
Q
  1. vector<int> numbers = { 1, 2, 3, 4 };</int>
A

You do not use an = operator before the initialization list.