Chapter 7 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
Any time the name of the array is used without brackets and a subscript, it is seen as ______.
an address
26
To pass an array to a function, pass the ______ of the array
address, or name
27
A(n) ______ array is like several arrays of the same type put together
multi-demensional
28
It is best to think of a two-dimensional array as having ______ and ______.
rows, columns
29
To define a two-dimensional array, ______ size declarators are required
two
30
When initializing a two-dimensional array, it helps to enclose each row's initialization list in ______.
braces
31
When initializing a two dimensional array, it helps to enclose each rows initialization list in ______.
braces
32
When a two dimensional array is passed to a function the ______ size must be specified.
column
33
The ______ is a collection of programmer defined data types and algorithms that you may use in your programs
Standard Template Library (STL)
34
The two types of containers defined by the STL are ______ and ______.
sequence, associative
35
The vector data type is a(n) ______ container.
sequence
36
To define a vector in your program, you must #include the ______ header file.
vector
37
To store a value in a vector that does not have a starting size, or that is already fill, use the ______ member function.
push_back
38
To determine the number of elements in a vector, use the ______ member function.
size
39
Use the ______ member function to remove the last element from a vector.
pop_back
40
To completely clear the contents of a vector, use the ______ member function.
clear
41
[T/F] | An array’s size declarator can be either a literal, named constant, or a variable.
False
42
[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.
True
43
[T/F] | The individual elements of an array are accessed and indexed by unique numbers.
True
44
[T/F] | The first element in an array is accessed by the subscript 1.
False
45
[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.
True
46
[T/F] | The contents of an array element cannot be displayed with cout.
False
47
[T/F] | Subscript numbers may be stored in variables.
True
48
[T/F] | You can write program that use invalid subscripts for an array.
True
49
[T/F] | Arrays cannot be initialized when they are defined. A loop of other means must be used.
False
50
[T/F] | The values in an initialization list are stored in the array in the order they appear in the list.
True
51
[T/F] | C++ allows you to partially initialize an array.
True
52
[T/F] | If an array is partially initialized, the uninitialized elements will contain “garbage.”
False
53
[T/F] | If you leave an element uninitialized, you do not have to leave all the ones that follow it uninitialized.
False
54
[T/F] | If you leave out the size declarator of an array definition, you do not have to include initialization list.
False
55
[T/F] | The uninitialized elements of a string array will automatically be set to the value “0″
False
56
[T/F] | You cannot use the assignment operator to copy one array’s contents to another in a single statement.
True
57
[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.
False
58
[T/F] | To pass an array to a function, pass the name of the array.
True
59
[T/F] When defining a parameter variable to hold a single dimensional array argument, you do not have to include the size declarator.
True
60
[T/F] | When an array is passed to a function, the function has access to the original array.
True
61
[T/F] | A two dimensional array is like several identical arrays put together.
True
62
[T/F] | It’s best to think of 2D arrays as having rows and columns.
True
63
[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.
False
64
[T/F] | 2D arrays may be passed to functions, but the row size must be specified in the definition of the parameter variable.
False
65
[T/F] | C++ allows you to create arrays with three or more dimensions.
True
66
[T/F] | A vector is an associative container.
False
67
[T/F] | To use a vector, you must include the vector header file.
True
68
[T/F] | Vectors can report the number of elements they contain.
True
69
[T/F] | You can use the [ ] operator to insert a value into a vector that has no elements.
False
70
[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.
True