Ch 7 Flashcards Preview

Computer Science Exam 3 > Ch 7 > Flashcards

Flashcards in Ch 7 Deck (30)
Loading flashcards...
1

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.

2

Look at the following array definition.
int values [10];
How many elements does this array have?
What is the subscript of the first element in the array?
What is the subscript of the last element in the array?
Four bytes of memory, how much memory does the array use?

The array has 10 elements.
The subscript of the first element is 0.
The subscript of the last element is 9.
Using four-byte integers, this array uses 40 bytes of memory

3

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

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

4

Consider the following array definition:
int values[5] = {4, 7, 6, 8, 2};
What does each of the following statements display?
cout << values[4] << endl; __
cout

2
14
8

5

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.

6

Look at the following array definition.
int number [5] = {1, 2, 3};
What value is stored in number [2]?
What value is stored in number [4]?

3
0

7

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

Because 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.

8

Assuming that numbers is an array of doubles, will the following statement display the contents of the array?
cout << numbers << endl;

no

9

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

By reference

10

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

The array's beginning memory address.

11

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

By using the same subscript value for each array

12

Look at the following array definition.
double sales [8][10];
How many rows, columns, and elements does the array have? Write a statement that stores a number in the last column of the last row in the array.

Eight rows
Ten columns
2 elements
sales[8][10] = 75.2;

13

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

The programmer must include the number of columns and number of rows.

14

What advantages does a vector offer over an array?

A vector is can be change its size but an array is a fixed size.

15

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

size declarator

16

The size declarator must be a(n) _________ with a value greater than _________.

integer
0

17

Each element of an array is accessed and indexed by a number known as a(n) _________.

subscript

18

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 _________.

size declarator
subscript

19

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

bounds

20

Starting values for the elements of an array may be specified with a(n) _________ list.

initialization

21

If an array is partially initialized, the uninitialized elements will be set to ____

zero

22

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

23

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

=

24

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

an address

25

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

address, or name

26

An ______ array is like several arrays of the same type put together.

multi-dimensional

27

t’s best to think of a two dimensional array as having ______ and ______.

rows, columns

28

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

two

29

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

braces

30

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

column