Chapter 7 Flashcards
What is the difference between a size declarator and a subscript?
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
Look at the following array definition:
int values [10];
How many elements does the array have?
10
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?
0
9
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?
40 bytes
Why should a function that accepts an array as an argument, and processes that array, also accept an argument specifying the array size?
Because, with the array alone, the function has no way of determining the number of elements it has.
How do you define an array without providing a size declarator?
By providing an initialization list. The array is sized to hold the number of values in the list
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;
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.
Is an array passed to a function by value or by reference?
By reference
When you pass an array name as an argument to a function, what is actually being passed?
The array’s beginning memory address
How do you establish a parallel relationship between two or more arrays?
By using the same subscript value for each array
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?
8 rows
10 columns
80 elements
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?
The second size declarator, which is for the number of columns
What advantages does a vector offer over an array?
- you dont have to declare the number of elements that a vector will have
- 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 vector can report the number of elements it contains
The ______ indicates the number of elements, or values, an array can hold.
size declarator
The size declarator must be a(n) ______ with a value greater than ______.
integer
0
Each element in an array is accessed and indexed by a number known as a(n) ______.
subscript
Subscript numbering in C++ always starts with ______.
0
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 ______.
size declarator
subscript
C++ has no array ______ checking, which means you can inadvertently store data past the end of an array
bounds
Starting values for an array may be specified with a(n) ______ list.
inititalization
If an array is partially initialized, the uninitialized elements will be set to ______.
0
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.
initialization list
By using the same ______ for multiple arrays, you can build relationships between the data stored in the arrays.
subscript
You cannot use the ____ operator to copy data from one array to another in a single statement.
assignment (=)
Any time the name of the array is used without brackets and a subscript, it is seen as ______.
an address
To pass an array to a function, pass the ______ of the array
address, or name
A(n) ______ array is like several arrays of the same type put together
multi-demensional
It is best to think of a two-dimensional array as having ______ and ______.
rows, columns