csci exam 3 Flashcards

1
Q

An array is an example of a structured data type (t/f)

A

true

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

All components of an array are of the same type (t/f)

A

true

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

If array index goes out of bounds, the program always terminates in an error. (t/f)

A

false

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

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

A

false

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

The word const is used before the array declaration in a function heading to prevent the function from modifying the array. (t/f)

A

true

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

The base address of an array is the memory location of the first array component. (t/f)

A

true

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

A function cannot return a value of the type array. (t/f)

A

true

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

Two arrays are parallel id they hold the same type of data. (t/f)

A

false

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

when a two-dimensional array is declared as a parameter, the C++ compiler ignores the sizes of both dimensions (t/f)

A

false

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

Which of the following statements declares alpha to be an array of 25 components of type int?

A

int alpha[25];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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 trough 99

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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 = 0; j < =9; j++)
cout &laquo_space;List[j] «” “;
cout &laquo_space;endl;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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 5 10 15 20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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

10 8 6 4 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
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 <= 50; j++)
cout &laquo_space;gamma[j] &laquo_space;” “;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
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};

17
Q

Consider the following declaration int alpha[3];. Which of the following statements correctly inputs values into alpha?

A

cin&raquo_space; alpha[0]
» alpha[1]
» alpha[2];

18
Q

Consider the following statement: double alpha[10][5];. The number of components in alpha is:

A

50

19
Q

Consider the statement int list[10][8];. Which of the following about list is true?

A

list has 10 rows and 8 columns

20
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 1
1 2
2 3

21
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[4][j];

22
Q

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?

A

sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][3];

23
Q

A struct is a homogeneous data structure with all components of the same type. (t/f)

A

false

24
Q

Both arrays and structs are examples of structured data types. (t/f)

A

True

25
Q

Memory is allocated when you define a struct. (t/f)

A

false

26
Q
A