Quiz 7 Flashcards
Given the declaration int list[20]; the statement list[12] = list[5] + list[7]; updates the content of the twelfth component of the array list.
A) True B) False
False
When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter.
A) True
B) False
True
All components of an array are of the same data type.
A) True
B) False
True
The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0.
A) True
B) False
False
Suppose that sales is an array of 50 components of type double. Which of the following correctly initializes the array sales?
A)
or (int 1 = 1; j <= 49; j++)
sales[j] = 0;
B) for (int j = 1; j <= 50; j++)
sales[j] = 0;
C) for (int j = 0; j <= 49; j++)
sales[j] = 0.0;
D) for (int j = 0; j <= 50; j++)
sales[j] = 0.0;
C) for (int j = 0; j <= 49; j++)
sales[j] = 0.0;
What is the value of alpha[2] after the following code executes?
int alpha[5];
int j;
for (j = 0; j < 5; j++)
alpha[j] = 2 * j + 1;
A) 1
B) 4
C) 5
D) 6
5
Given the following declaration:
int j;
int sum;
double sale[10][7];
which of the following correctly finds the sum of the elements of the fifth row of sale?
A)
sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[5][j];
B)
sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[4][j];
C)
sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[5][j];
D)
sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[4][j];
B)
sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[4][j];
Consider the statement int list[10][8];. Which of the following about list is true?
A) list has 10 rows and 8 columns.
B) list has 8 rows and 10 columns.
C) list has a total of 18 components.
D) list has a total of 108 components.
A) list has 10 rows and 8 columns.
What is the output of the following C++ code?
int list[5] = {0, 5, 10, 15, 20};
int j;
for (j = 1; j <= 5; j++)
cout «_space;list[j] «_space;” “;
cout «_space;endl;
A) 0 5 10 15 20
B) 5 10 15 20 0
C) 5 10 15 20 20
D) Code results in index out-of-bounds
D) Code results in index out-of-bounds
What is the output of the following C++ code?
int list[5] = {0, 5, 10, 15, 20};
int j;
for (j = 0; j < 5; j++)
cout «_space;list[j] «_space;” “;
cout «_space;endl;
A) 0 1 2 3 4
B) 0 5 10 15
C) 0 5 10 15 20
D) 5 10 15 20
C) 0 5 10 15 20
Assume you have the following declaration int beta[50];. Which of the following is a valid element of beta?
A) beta[‘2’]
B) beta[‘50’]
C) beta[0]
D) beta[50]
C) beta[0]
Consider the following declaration: int alpha[5] = {3, 5, 7, 9, 11};. Which of the following is equivalent to this statement?
A) int alpha[] = {3, 5, 7, 9, 11};
B) int alpha[] = {3 5 7 9 11};
C) int alpha[5] = [3, 5, 7, 9, 11];
D) int alpha[] = (3, 5, 7, 9, 11);
A) int alpha[] = {3, 5, 7, 9, 11};
Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the following for loops sets the index of gamma out of bounds?
A)
for (j = 0; j <= 49; j++)
cout «_space;gamma[j] «_space;” “;
B)
for (j = 1; j < 50; j++)
cout «_space;gamma[j] «_space;” “;
C)
for (j = 0; j <= 50; j++)
cout «_space;gamma[j] «_space;” “;
D)
for (j = 0; j <= 48; j++)
cout «_space;gamma[j] «_space;” “;
C)
for (j = 0; j <= 50; j++)
cout «_space;gamma[j] «_space;” “;
After the following statements execute, what are the contents of matrix?
int matrix[3][2];
int j, k;
for (j = 0; j < 3; j++)
for (k = 0; k < 2; k++)
matrix[j][k] = j + k;
A)
0 0
1 1
2 2
B)
0 1
2 3
4 5
C)
0 1
1 2
2 3
D)
1 1
2 2
3 3
C)
0 1
1 2
2 3
Suppose list is a one dimensional array of size 25, wherein each component is of type int. Further, suppose that sum is an int variable. The following for loop correctly finds the sum of the elements of list.
sum = 0;
for (int i = 0; i < 25; i++)
sum = sum + list;
A) True B) False
False
If an array index goes out of bounds, the program always terminates in an error.
A) True B) False
False
Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference.
A) True B) False
False
In a two-dimensional array, the elements are arranged in a table form.
A) True B) False
True
Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for the index of the array nameList?
A) 0 through 99
B) 0 through 100
C) 1 through 100
D) 1 through 101
A) 0 through 99
Assume you have the following declaration double salesData[1000];. Which of the following ranges is valid for the index of the array salesData?
A) 0 through 999
B) 0 through 1000
C) 1 through 1001
D) 1 through 1000
A) 0 through 999
Consider the following statement: int alpha[25][10];. Which of the following statements about alpha is true?
A) Rows of alpha are numbered 0…24 and columns are numbered 0…9.
B) Rows of alpha are numbered 0…24 and columns are numbered 1…10.
C) Rows of alpha are numbered 1…24 and columns are numbered 0…9.
D) Rows of alpha are numbered 1…25 and columns are numbered 1…10.
A) Rows of alpha are numbered 0…24 and columns are numbered 0…9.
Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the elements of list?
A)
for (int j = 1; j < 10; j++)
cout «_space;list[j] «_space;” “;
cout «_space;endl;
B)
for (int j = 0; j <= 9; j++)
cout «_space;list[j] «_space;” “;
cout «_space;endl;
C)
for (int j = 1; j < 11; j++)
cout «_space;list[j] «_space;” “;
cout «_space;endl;
D)
for (int j = 1; j <= 10; j++)
cout «_space;list[j] «_space;” “;
cout «_space;endl;
B)
for (int j = 0; j <= 9; j++)
cout «_space;list[j] «_space;” “;
cout «_space;endl;
What is the output of the following C++ code?
int alpha[5] = {2, 4, 6, 8, 10};
int j;
for (j = 4; j >= 0; j–)
cout «_space;alpha[j] «_space;” “;
cout «_space;endl;
A)
2 4 6 8 10
B)
4 3 2 1 0
C)
8 6 4 2 0
D)
10 8 6 4 2
D)
10 8 6 4 2
Which of the following statements declares alpha to be an array of 25 components of the type int?
A) int alpha[25];
B) int array alpha[25];
C) int alpha[2][5];
D) int array alpha[25][25];
A) int alpha[25];
In a two-dimensional array, the elements are arranged in a table form.
A) True B) False
True