Chapter 7 Arrays and Vectors Review Questions.

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

0

Subscript numbering in C++ always starts at _______

0

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 << (values[2] + values[3]) << endl; cout << ++values[1] << endl;

2 14 8

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

3 0

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

=

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.

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.

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.

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

By reference.

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? Write a statement that stores a number in the last column of the last row in the array.

Eight rows Ten columns Eighty elements sales[7][9] = 123.45;

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

No.

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

Standard Template Library (or STL)

Look at the following array definition: int values[10]; How many elements does the array have? What is the subscript of the first element in the array? What is the subscript of the last element in the array? Assuming that an int uses 4 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.

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

The array's beginning memory address.

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

What advantages does a vector offer over an array?

You do not 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.

to pass an array to a function, pass the _______of the array.

address, or name

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

an address

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

bounds

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

braces

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

clear

When a two-dimensional array is passed to a function, the ________ size must be specified.

column

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

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

false

T F A vector is an associative container.

false ( A vector is a container that can store data.)

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

false ( C++ allows you to initialize an array's elements when you create the array.)

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

false (Array elements may be used with the cin and cout objects like any other variable.)

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

false (It's possible to define an array without specifying its size, as long as you provide an initialization list.)

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

false (The first element is assigned the subscript 0)

T F The uninitialized elements of a string array will automatically be set to the value "0".

false (The uninitialized elements of a string array will contain empty strings.)

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

false (When a two-dimensional array is passed to a function, the parameter type must contain a size declarator for the number of columns. )

T F 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.

false (the first one is for the number of rows, and the second one is for the number of columns.)

T F If an array is partially initialized, the uninitialized elements will contain "garbage."

false (the uninitialized elements will be set to zero.)

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

false (you must leave all the elements that follow it uninitialized as well. )

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

initialization

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

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

integer, 0

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

multi-dimensional

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

pop-back()

It's best to think of a two-dimensional array as having _____ and _______ .

rows, columns

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

sequence

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

sequence and associative

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

size declarator

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

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

subscript

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

subscript

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

true

T F An array's size declarator must be a constant integer expression with a value greater than zero. It can be either a literal, as in the previous example, or a named constant.

true

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

true

T F C++ allows you to partially initialize an array.

true

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

true

T F Subscript numbers may be stored in variables.

true

T F The individual elements of an array are assigned unique subscripts. These subscripts are used to access the elements.

true

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

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

true

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

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

true

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

true

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

true

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

true

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

true

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

true

T F vectors can report the number of elements they contain.

true

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

To define a two-dimensional array, _____size declarators are required.

two

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

vector


Kaugnay na mga set ng pag-aaral

The Family: Chapter 2 the Family in History

View Set

Managerial Accounting, 4e (Whitecotton) Chapter 3 Process Costing

View Set

Quiz 8 covers Lecture 12 Blood Vessels and Blood Pressure.

View Set