Quiz 7 Flashcards

1
Q

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
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

All components of an array are of the same data type.
A) True
B) False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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;

A

C) for (int j = 0; j <= 49; j++)
sales[j] = 0.0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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];

A

B)
sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[4][j];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A) list has 10 rows and 8 columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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 &laquo_space;list[j] &laquo_space;” “;
cout &laquo_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

A

D) Code results in index out-of-bounds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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 &laquo_space;list[j] &laquo_space;” “;
cout &laquo_space;endl;

A) 0 1 2 3 4

B) 0 5 10 15

C) 0 5 10 15 20

D) 5 10 15 20

A

C) 0 5 10 15 20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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]

A

C) beta[0]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A) int alpha[] = {3, 5, 7, 9, 11};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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 &laquo_space;gamma[j] &laquo_space;” “;

B)
for (j = 1; j < 50; j++)
cout &laquo_space;gamma[j] &laquo_space;” “;

C)
for (j = 0; j <= 50; j++)
cout &laquo_space;gamma[j] &laquo_space;” “;

D)
for (j = 0; j <= 48; j++)
cout &laquo_space;gamma[j] &laquo_space;” “;

A

C)
for (j = 0; j <= 50; j++)
cout &laquo_space;gamma[j] &laquo_space;” “;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

C)
0 1
1 2

2 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If an array index goes out of bounds, the program always terminates in an error.

A) True
B) False
17
Q

Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference.

A) True
B) False
18
Q

In a two-dimensional array, the elements are arranged in a table form.

A) True
B) False
19
Q

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

A) 0 through 99

20
Q

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

A) 0 through 999

21
Q

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

A) Rows of alpha are numbered 0…24 and columns are numbered 0…9.

22
Q

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 &laquo_space;list[j] &laquo_space;” “;
cout &laquo_space;endl;

B)
for (int j = 0; j <= 9; j++)
cout &laquo_space;list[j] &laquo_space;” “;
cout &laquo_space;endl;

C)
for (int j = 1; j < 11; j++)
cout &laquo_space;list[j] &laquo_space;” “;
cout &laquo_space;endl;

D)
for (int j = 1; j <= 10; j++)
cout &laquo_space;list[j] &laquo_space;” “;
cout &laquo_space;endl;

A

B)
for (int j = 0; j <= 9; j++)
cout &laquo_space;list[j] &laquo_space;” “;
cout &laquo_space;endl;

23
Q

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 &laquo_space;alpha[j] &laquo_space;” “;

cout &laquo_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

A

D)
10 8 6 4 2

24
Q

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

A) int alpha[25];

25
Q

In a two-dimensional array, the elements are arranged in a table form.

A) True
B) False