WorksheetsC++ Array
Total questions: 28
Worksheet time: 1hrs 24mins
Unlike regular variables, __________ can hold multiple values.
constants
named constants
arrays
floats
To access an array element, use the array name and the element's ___________.
data type
subscript
value
name
The name of an array stores the __________ of the first array element.
value
memory address
element number
data type
Given the following declaration, where is the value 77 stored in the scores array?
int scores[] = {83, 62, 77, 97, 86}
scores[0]
scores[1]
scores[2]
scores[3]
What is the last legal subscript that can be used with the following array?
int values[5];
0
5
6
4
To pass an array as an argument to a function, pass the __________ of the array.
contents
size, expressed as an integer
name
value of the first element
What will the following code display?
int numbers[5] = {99, 87, 66, 55, 101};
for (int i = 1; i < 4; i++)
cout << numbers[i] << " ";
99 87 66 55 101
87 66 55 101
87 66 55
Nothing. This code has an error.
A two-dimensional array can be viewed as
rows and columns
arguments and parameters
increments and decrements
All of these
An element of a two-dimensional array is referred to by
the array name followed by the column number of the element
the row subscript of the element followed by the column subscript of the element
a comma followed by a semicolon
the row subscript of the element followed by the array name
An element of a two-dimensional array is referred to by
the array name followed by the column number of the element
the row subscript of the element followed by the column subscript of the element
a comma followed by a semicolon
the row subscript of the element followed by the array name
An array of string objects that will hold five names would be declared with which of the following statements?
string names[5];
string names(5);
string names 5;
String[5] = names;
A single value in an array is addressed by specifying…
the name of the array followed by the index of the element.
the name of the array ONLY.
the index of the element followed by the name of the array.
the index of the element in the array ONLY.
Which of the following is a valid C++ array definition?
int array[0];
float $$payments[10];
void numbers[5];
int nums[10];
The subscript (or index) of an array can be…
an integer
a floating point number
a character
a negative number
What does the following code do?
for (int index = 0; index < 5; index++)
cin >> numbers[index];
Place data into a four element array called numbers.
Place data into a four element array called index.
Place data into a five element array called numbers.
Place data into a five element array called index.
Which of the following array declarations is invalid?
bool array1[10];
double array2[20,0];
char array3[30];
double array4[7];
In the statement a[3] = 5, which of the following is the index value?
a
3
a[3]
5
If you leave out the size declarator in an array definition:
You must provide an initialization list
You are not required to initialize the array elements
All array elements default to zero values
Your array will contain no elements
An array can store a group of values, but the values must be…
the same data type
each of a different data type
constants
integers
What is the last legal subscript that can be used with the following array?
int values[5];
0
5
6
4
Given the following declaration, where is 77 stored in the scores array?
int scores[]={83, 62, 77, 97};
scores[0]
scores[1]
scores[2]
scores[3]
What will the following code do?
const int SIZE = 5;
double x[SIZE];
for(int i = 2; i <= SIZE; i++)
{
x[i] = 0.0;
}
Each element in the array is initialized to 0.0
Each element in the array, except the first, is initialized to 0.0
Each element in the array, except the first and the last, is initialized to 0.0
An error will occur when the code runs
To indicate that 100 locations should be reserved for the integer array p, the programmer should write the declaration int p[99];
True
False
A function is designed to identify the position of the largest value in an array. The function is sent an integer array and the size of the array (25). Which of the following function declarations is correct?
int largest_value( int a[25])
largest_value (int a[], int 25)
int largest_value (int a[], int size)
int largest_value (int a[], size)
To assign the contents of one array to another, you must use…
the assignment operator with the array names
the equality operator with the array names
a loop to assign the elements of one array to the other
To assign the contents of one array to another, you must use…
the assignment operator with the array names
the equality operator with the array names
a loop to assign the elements of one array to the other
C++ limits the number of array dimensions to two.
True
False
When you pass an array into a function as an argument:
the function can modify the contents of the array
the function has a new copy of the array
