csci exam 3 Flashcards
An array is an example of a structured data type (t/f)
true
All components of an array are of the same type (t/f)
true
If array index goes out of bounds, the program always terminates in an error. (t/f)
false
Arrays can be passed as parameters to a functions by value, but it is faster to pass them by reference.
false
The word const is used before the array declaration in a function heading to prevent the function from modifying the array. (t/f)
true
The base address of an array is the memory location of the first array component. (t/f)
true
A function cannot return a value of the type array. (t/f)
true
Two arrays are parallel id they hold the same type of data. (t/f)
false
when a two-dimensional array is declared as a parameter, the C++ compiler ignores the sizes of both dimensions (t/f)
false
Which of the following statements declares alpha to be an array of 25 components of type int?
int alpha[25];
Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for the index of the array nameList?
0 trough 99
Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the elements of list?
for (int j = 0; j < =9; j++)
cout «_space;List[j] «” “;
cout «_space;endl;
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;
0 5 10 15 20
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;
10 8 6 4 2
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?
for (j = 0; j <= 50; j++)
cout «_space;gamma[j] «_space;” “;
Consider the following declaration int alpha[5] = {3, 5, 7, 9, 11};. Which of the following is equivalent to this statement?
int alpha[] = {3, 5, 7, 9, 11};
Consider the following declaration int alpha[3];. Which of the following statements correctly inputs values into alpha?
cin»_space; alpha[0]
» alpha[1]
» alpha[2];
Consider the following statement: double alpha[10][5];. The number of components in alpha is:
50
Consider the statement int list[10][8];. Which of the following about list is true?
list has 10 rows and 8 columns
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;
0 1
1 2
2 3
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?
sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[4][j];
Given the following declaration:
int l;
int sum;
double sale[10][7];
Which of the following correctly finds the sum of the elements of the fourth column of sale?
sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][3];
A struct is a homogeneous data structure with all components of the same type. (t/f)
false
Both arrays and structs are examples of structured data types. (t/f)
True