Chapter 7 C++

¡Supera tus tareas y exámenes ahora con Quizwiz!

What will the following code display? int numbers[4] = {99, 87}; cout << numbers[3] << endl;

0

How many elements does the following array have? int values [1000];

1000

What will the following code display? vector <int> numbers (3,5); for (int val:numbers) cout << val <<endl;

3 5

What is the last legal subscript that can be used with the following array? int values [5];

4

What will the following code display? 49) int numbers[] = {99, 87, 66, 55, 101}; cout << numbers[3] << endl;

55

What will the following code display? 50) int numbers[] = {99, 87, 66, 55, 101}; for (int i = 1; i < 4; i++) cout << numbers[i] << " ";

87 66 55

A two- dimensional array of characters can contain

All of these

What does the following code do? 52) const int SIZE = 5;double x[SIZE];for (int i = 2; i <= SIZE; i++) { x[i] = 0.0; }

An error will occur when the code runs

Although two-dimensional arrays are novel idea, there is no known way to pass one to a function.

False

An array initialization list must be placed on one single line.

False

Assume array1 and array2 are the names of two arrays. To assign the contents of array2 to array1, you would use the following statement: array1= array2;

False

C++ limits the number of array dimensions to two.

False

If you attempt to store data past an array's boundaries, it is guaranteed to cause a compiler error.

False

The following statement is a valid C++ definition: double money [25.00];

False

The range based for loop only works with arrays. It cannot be used with vectors.

False

The range- based for loop is best used in situations where you need the element subscript for some purpose.

False

What does the following statement do? vector<int> v(10,2);

It creates a vector object with a starting size of 10 and initializes all the elements with the value 2

A vector object automatically expands in size to accommodate the items stored in it.

True

After the following code executes, the variable n2 will be assigned the value2: int narray[ ] = {1,2,3}; auto [n1,n2,n3] = narray;

True

An error will occur if you use the subscript operator to try to access a nonexistent vector element.

True

An individual array element can be processed like any other type C++ variable.

True

Each individual element of an array can be accessed by the array name and the element subscript.

True

If an array has been passed as an argument into a function, you cannot use a structured binding declaration in the receiving function to unpack the array.

True

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

True

The amount of memory used by an array depends on the array's data type and the number of elements in the array.

True

When you pass an array as an argument to a function, the function can modify the contents of the array.

True

You cannot use a range-based for loop to modify the contents of an array unless you declare the range variable as a reference variable.

True

An array can easily be stepped through by using

a for loop

To assign the contents of one array to another, you must use

a loop to assign the elements of one array to the other array

When writing a function that accept multi-dimensional arrays as arguments, ____ must be explicitly stated in the parameter list.

all but the first dimension

Unlike regular variables, _______ can hold multiple variables.

arrays

Subscript number in C++

begins with zero

An array's size declarator must be a ______ with a value greater than ______.

constant integer expression, zero

The individual values contained in an array are known as

elements

This vector function returns true if the vector has no elements.

empty

An array with no elements is

illegal in C++

This following statement shows an example of ______. int grades[ ] = {100, 90, 99, 80};

implicit array sizing

A(n) _______ can be used to specify the starting values of an array.

initialization list

Arrays must be ______ at the time they are _______.

initialized, declared

Which of the following is a valid C++ array definition?

int scores[25];

Which of the following is a valid C++ array definition?

int sizes[10];

What does the following statement do? vector<int> v(10);

it created a vector object with a starting size of 10

The name of an array stores the _______ of the first array element.

memory address

To pass an array as an argument to a function, pass the _______ of the array.

name

The ______ is automatically appended to a character array when it is initialized with a string constant.

null terminator

A two- dimensional array can have elements of ______ data type(s).

one

This vector function removes an item from a vector.

pop_back

This vector function is used to insert an item into a vector.

push_back

A two- dimensional array can be viewed as

rows and columns

Given the following declaration, where is the value 77 stored in the scores array? int scores [ ] = {83, 62, 77, 97, 86}

scores[2]

This vector function returns the number of elements in a vector.

size

An array of string objects that will hold five names would be declared with which of the following statements?

string names[5];

Assuming narray is an int array, what type of statement is this? auto [ v1, v2, v3] = narray;

structured binding declaration

By using the same _______ you can build relationships between data stored in two or more arrays.

subscript

To access an array element, use the array name and the element's

subscript

The range based for loop is designed to work with a built-in variable known as

the range variable

An element of a two-dimensional array is referred to by

the row subscript of the element followed by the column subscript of the element

An array can store a group of values, but the values must be

the same data type

Which statement correctly initializes a vector of ints named n with the values 10 and 20?

vector <int> n {10,20};

Which statement correctly defines a vector object for holding images?

vector <int> v;

If you leave out the size declarator in an array definition?

you must furnish an initialization


Conjuntos de estudio relacionados

Chapter 1: Purpose and Importance of Accounting

View Set

Ch. 13: Management of Financial Resources

View Set

Automotive Theory and Maintenance Units 1-4 Study Guide

View Set

Lab 12 - Reptiles Assignment connect ed mcgraw hill zoology

View Set

Ch. 51: Management of Patients with Immunodeficiency

View Set

The Internet, Chapter 7, "The Public Sphere"

View Set

Nursing Health Alterations Exam 3

View Set