Chapter 7 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the difference between a size declarator and a subscript?

A

The size declarator is used in a definition of an array to indicate the number of elements the array will have.
A subscript is used to access a specific element in an array

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

Look at the following array definition:

int values [10];

How many elements does the array have?

A

10

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

Look at the following array definition:

int values [10];

What is the subscript of the first element in the array?
What is the subscript of the last element in the array?

A

0

9

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

Look at the following array definition:

int values [10];

Assuming that an int uses four bytes of memory, how much memory does the array use?

A

40 bytes

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

Why should a function that accepts an array as an argument, and processes that array, also accept an argument specifying the array size?

A

Because, with the array alone, the function has no way of determining the number of elements it has.

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

How do you define an array without providing a size declarator?

A

By providing an initialization list. The array is sized to hold the number of values in the list

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

Assuming that array1 and array 2 are both arrays, why is it not possible to assign the contents of array2 to array1 with the following statement?

array1 = array2;

A

An array name without brackets and a subscript represents the array’s beginning memory address. The statement shown attempts to assign the address of array2 to array1, which is not permitted.

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

Is an array passed to a function by value or by reference?

A

By reference

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

When you pass an array name as an argument to a function, what is actually being passed?

A

The array’s beginning memory address

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

How do you establish a parallel relationship between two or more arrays?

A

By using the same subscript value for each array

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

Look at the following array definition:

double sales [8] [10];

How many rows does the array have?
How many columns does the array have?
How many elements does the array have?

A

8 rows
10 columns
80 elements

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

When writing a function that accepts a two-dimensional array as an argument, which size declarator must you provide in the parameter for the array?

A

The second size declarator, which is for the number of columns

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

What advantages does a vector offer over an array?

A
  1. you dont have to declare the number of elements that a vector will have
  2. If you add a value to a vector that is already full, the vector will automatically increase its size to accommodate the new value
  3. a vector can report the number of elements it contains
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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
15
Q

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
16
Q

Each element in 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
17
Q

Subscript numbering in C++ always starts with ______.

A

0

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

The number inside the brackets of an array definition is the ______, but the number inside an array’s brackets is 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
19
Q

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

A

bounds

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

Starting values for an array may be specified with a(n) ______ list.

A

inititalization

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

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
22
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
23
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
24
Q

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

A

assignment (=)

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

Any time the name of the 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
26
Q

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
27
Q

A(n) ______ array is like several arrays of the same type put together

A

multi-demensional

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

It is 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
29
Q

To define a two-dimensional array, ______ size declarators are required

A

two

30
Q

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

A

braces

31
Q

When initializing a two dimensional array, it helps to enclose each rows initialization list in ______.

A

braces

32
Q

When a two dimensional array is passed to a function the ______ size must be specified.

A

column

33
Q

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

A

Standard Template Library (STL)

34
Q

The two types of containers defined by the STL are ______ and ______.

A

sequence, associative

35
Q

The vector data type is a(n) ______ container.

A

sequence

36
Q

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

A

vector

37
Q

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

A

push_back

38
Q

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

A

size

39
Q

Use the ______ member function to remove the last element from a vector.

A

pop_back

40
Q

To completely clear the contents of a vector, use the ______ member function.

A

clear

41
Q

[T/F]

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

A

False

42
Q

[T/F]
To calculate the amount of memory used by an array, multiply the number of elements by the number of bytes each element uses.

A

True

43
Q

[T/F]

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

A

True

44
Q

[T/F]

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

A

False

45
Q

[T/F]
The subscript of the last element in a single dimensional array is one less than the total number of elements in the array.

A

True

46
Q

[T/F]

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

A

False

47
Q

[T/F]

Subscript numbers may be stored in variables.

A

True

48
Q

[T/F]

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

A

True

49
Q

[T/F]

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

A

False

50
Q

[T/F]

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

A

True

51
Q

[T/F]

C++ allows you to partially initialize an array.

A

True

52
Q

[T/F]

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

A

False

53
Q

[T/F]

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

A

False

54
Q

[T/F]

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

A

False

55
Q

[T/F]

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

A

False

56
Q

[T/F]

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

A

True

57
Q

[T/F]

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

58
Q

[T/F]

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

A

True

59
Q

[T/F]
When defining a parameter variable to hold a single dimensional array argument, you do not have to include the size declarator.

A

True

60
Q

[T/F]

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

A

True

61
Q

[T/F]

A two dimensional array is like several identical arrays put together.

A

True

62
Q

[T/F]

It’s best to think of 2D arrays as having rows and columns.

A

True

63
Q

[T/F]
The first size declarator (in the declaration of a 2D array) represents the number of columns. The second size definition represents the number of rows.

A

False

64
Q

[T/F]

2D arrays may be passed to functions, but the row size must be specified in the definition of the parameter variable.

A

False

65
Q

[T/F]

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

A

True

66
Q

[T/F]

A vector is an associative container.

A

False

67
Q

[T/F]

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

A

True

68
Q

[T/F]

Vectors can report the number of elements they contain.

A

True

69
Q

[T/F]

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

A

False

70
Q

[T/F]
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