QUESTION 20
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;
1. 1
2. 4
3. 5
4. 6
QUESTION 23
Suppose that gamma is an array of 50 elements of type int and j is an int variable. Which of the following for loops
sets the subscript of gamma out-of-range?
1. for (j = 0; j <= 49; j++)
cout << gamma[j] << " ";
2. for (j = 1; j < 50; j++)
cout << gamma[j] << " ";
3. for (j = 0; j <= 50; j++)
cout << gamma[j] << " ";
4. for (j = 0; j <= 48; j++)
cout << gamma[j] << " ";
QUESTION 17
Suppose that sales is an array of 50 elements of type float. Which of the following correctly initializes the array
sales?
1. for (int 1 = 1; j <= 49; j++)
sales[j] = 0;
2. for (int j = 1; j <= 50; j++)
sales[j] = 0;
3. for (int j = 0; j <= 49; j++)
sales[j] = 0.0;
4. for (int j = 0; j <= 50; j++)
sales[j] = 0.0;
QUESTION 18
Suppose that list is an array of 10 elements of type int. Which of the following codes correctly outputs all the elements
of list?
1. for (int j = 1; j < 10; j++)
cout << list[j] << " ";
cout << endl;
2. for (int j = 0; j <= 9; j++)
cout << list[j] << " ";
cout << endl;
3. for (int j = 1; j < 11; j++)
cout << list[j] << " ";
cout << endl;
4. for (int j = 1; j <= 10; j++)
cout << list[j] << " ";
cout << endl;
QUESTION 15
Assume you have the following declaration
int beta[50];
Which of the following is a valid element of beta?
1. beta['2']
2. beta["50 "]
3. beta[0]
4. beta[50]
QUESTION 16
Assume the following declarations
const int NUMROWS = 3;
const int NUMCOLS = 4;
int val[NUMROWS][NUMCOLS]={8,16,9,52,3,15,27,6,14,25,2,10};
Which statement will change the value of the element with the value 27 to 55.
1. val[0][1] = 55;
2. val[1][2] = 55;
3. val[1][1] = 55;
4. val[2][1] = 55;
QUESTION 13
Which of the following statements declares alpha to be an array of 25 elements of the type int?
1. int alpha[25];
2. int array alpha[25];
3. int array alpha[25][25];
4. int alpha[2][5];
QUESTION 14
Assume you have the following declaration
char nameList[100];
Which of the following ranges is valid for the subscript of the array nameList?
1. 0 through 99
2. 0 through 100
3. 1 through 100
4. 1 through 101
QUESTION 9
Which of the following function header correctly includes a two dimensional array as its parameter?
1. void display(int [ROWS][]);
2. void display(int [][]);
3. void display(int [ROWS][COLS]);
4. void display(int [][COLS]);
QUESTION 8
Assuming the following declarations:
const int NUMROWS = 3;
const int NUMCOLS = 4;
int val[NUMROWS][NUMCOLS] = {8,16,9,52,3,15,27,6,14,25,2,10};
Which of the following loops correctly outputs each element of the array in row order?
1. for (i = 0; i < NUMROWS; i++)
{
for (j = 0; j < NUMCOLS; j++)
cout << setw(4) << val[i][j];
cout << endl;
}
2. for (i = 0; i < NUMROWS; i++)
{
cout << setw(4) << val[i][j];
cout << endl;
}
3. for (i = 0; i < NUMCOLS; i++)
{
cout << setw(4) << val[i][j];
cout << endl;
}
4. for (i = 0; i < NUMROWS*NUMCOLS; i++)
{
cout << setw(4) << val[i][j];
cout << endl;
}
QUESTION 7
Which of the following declarations correctly declares a two dimensional array of floats named prices that has 10
rows and 5 columns?
1. const int NUMROWS = 10;
const int NUMCOLS = 5;
float prices[NUMROWS + NUMCOLS];
2. const int NUMROWS = 10;
const int NUMCOLS = 5;
float prices[NUMROWS,NUMCOLS];
3. const int NUMROWS = 10;
const int NUMCOLS = 5;
float prices[NUMCOLS][NUMROWS];
4. const int NUMROWS = 10;
const int NUMCOLS = 5;
float prices[NUMROWS][NUMCOLS];
QUESTION 5
Consider the following declaration:
char codes[] = {'s', 'a', 'm', 'p', 'l', 'e'};
Which of the following array declarations is equivalent to the above declaration?
1. char codes[] = "sample";
2. char codes[5] = {'s', 'a', 'm', 'p', 'l', 'e'};
3. char codes[6] = {'s', 'a', 'm', 'p', 'l', 'e'};
4. char codes[7] = {'s', 'a', 'm', 'p', 'l', 'e'};
QUESTION 6
Which of the following function header lines is valid for a function called findMax that finds and returns the maximum
value stored in an array of integers that is passed in as a parameter?
1. int findMax(int [])
2. int findMax(int)
3. int findMax(int values[])
4. int findMax([])
QUESTION 3
Considering the following declarations:
const int NUMELS 10;
int values[NUMELS];
Which of the following C++ statements correctly outputs the seventh element of the array?
1. cout << values << 7;
2. cout << values[6];
3. cout << values[7];
4. cout << values[8];
QUESTION 4
Consider the following declarations:
const int ARRAYSIZE = 7;
float length[ARRAYSIZE] = {7.8, 6.4, 4.9, 11.2};
What is the value of length[1] and length[4]?
1. 7.8 and 11.2, respectively
2. 6.4 and 11.2, respectively
3. 7.8 and 0, respectively
4. 6.4 and 0, respectively
QUESTION 1
Consider the following declarations:
const int NUMELS 10;
int values[NUMELS];
Which of the following array accesses is valid?
1. values[-1]
2. values[10]
3. values[0]
4. values[11]
QUESTION 2
Consider the following code segment that finds the maximum value store in an array named grade of size NUMELS.
What is the missing line of code indicated by the blank line?
___________
for (i = 1; i < NUMELS; i++)
if (grade[i] > maximum)
maximum = grade[i];
1. maximum = grade[1];
2. maximum = grade[0];
3. maximum = 100;
4. maximum = grade[NUMELS];