Deck 8: Arrays and Strings

Full screen (f)
exit full mode
Question
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];
Use Space or
up arrow
down arrow
to flip the card.
Question
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]
Question
In a two-dimensional array,the elements are arranged in a table form.
Question
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 << alpha[j] << " ";
Cout << 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
Question
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
Question
The one place where C++ allows aggregate operations on arrays is the input and output of C-strings.
Question
The statement int list[25]; declares list to be an array of 26 components,since the array index starts at 0.
Question
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
Question
When you pass an array as a parameter,the base address of the actual array is passed to the formal parameter.
Question
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.
Question
All components of an array are of the same data type.
Question
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
Question
Suppose that sales is an array of 50 components of type double.Which of the following correctly initializes the array sales?

A) for (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;
Question
If an array index goes out of bounds,the program always terminates in an error.
Question
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 << list[j] << " ";
Cout << 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
Question
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 << list[j] << " ";
Cout << endl;

A) 0 1 2 3 4
B) 0 5 10 15
C) 0 5 10 15 20
D) 5 10 15 20
Question
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;
Question
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 << list[j] << " ";
Cout << endl;
B) for (int j = 0; j <= 9; j++)
Cout << list[j] << " ";
Cout << endl;
C) for (int j = 1; j < 11; j++)
Cout << list[j] << " ";
Cout << endl;
D) for (int j = 1; j <= 10; j++)
Cout << list[j] << " ";
Cout << endl;
Question
The array index can be any integer less than the array size.
Question
Arrays can be passed as parameters to a function by value,but it is faster to pass them by reference.
Question
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
Question
In a(n)____________________ data type,each data item is a collection of other data items.
Question
Which of the following correctly declares and initializes alpha to be an array of four rows and three columns with the component type int?

A) int alpha[4][3] = {{0,1,2} {1,2,3} {2,3,4} {3,4,5}};
B) int alpha[4][3] = {0,1,2; 1,2,3; 2,3,4; 3,4,5};
C) int alpha[4][3] = {0,1,2: 1,2,3: 2,3,4: 3,4,5};
D) int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}};
Question
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 fourth column of sale?

A) sum = 0;
For(j = 0; j < 7; j++)
Sum = sum + sale[j][3];
B) sum = 0;
For(j = 0; j < 7; j++)
Sum = sum + sale[j][4];
C) sum = 0;
For(j = 0; j < 10; j++)
Sum = sum + sale[j][4];
D) sum = 0;
For(j = 0; j < 10; j++)
Sum = sum + sale[j][3];
Question
In row order form,the ____.

A) first row is stored first
B) first row is stored last
C) first column is stored first
D) first column is stored last
Question
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);
Question
The ____________________ of an array is the address (that is,the memory location)of the first array component.
Question
In C++,the null character is represented as ____.

A) '\0'
B) "\0"
C) '0'
D) "0"
Question
The word ____________________ is used before the array declaration in a function heading to prevent the function from modifying the array.
Question
Complete the following statement so that it outputs the array sales.
double sales[10];
int index;
for (index = 0; index < 10; index++)
cout << ____________________ << " ";
Question
Which of the following correctly declares name to be a character array and stores "William" in it?

A) char name[6] = "William";
B) char name[7] = "William";
C) char name[8] = "William";
D) char name[8] = 'William';
Question
A data type is called ____________________ if variables of that type can store only one value at a time.
Question
Consider the following declaration: char str[15];.Which of the following statements stores "Blue Sky" into str?

A) str = "Blue Sky";
B) str[15] = "Blue Sky";
C) strcpy(str, "Blue Sky");
D) strcpy("Blue Sky");
Question
Consider the following declaration: char charArray[51];
Char discard;
Assume that the input is:
Hello There!
How are you?
What is the value of discard after the following statements execute?
Cin)get(charArray,51);
Cin)get(discard);

A) discard = ' ' (Space)
B) discard = '!'
C) discard = '\n'
D) discard = '\0'
Question
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.
Question
Consider the following statement: double alpha[10][5];.The number of components of alpha is ____.

A) 15
B) 50
C) 100
D) 150
Question
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.
Question
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];
Question
A collection of a fixed number of elements (called components)arranged in n dimensions (n>=1)is called a(n)____.

A) matrix
B) vector
C) n-dimensional array
D) parallel array
Question
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 << gamma[j] << " ";
B) for (j = 1; j < 50; j++)
Cout << gamma[j] << " ";
C) for (j = 0; j <= 50; j++)
Cout << gamma[j] << " ";
D) for (j = 0; j <= 48; j++)
Cout << gamma[j] << " ";
Question
The following statements store the value ____________________ into len.
int len;
len = strlen("Sunny California");
Question
For a list of length n,the ____________________ sort makes exactly (n(n - 1))/2 key comparisons and 3(n-1)item assignments.
Question
Two (or more)arrays are called ____________________ if their corresponding components hold related information.
Question
The declaration char str[] = "Hello there"; declares str to be a string of ____________________ characters.
Question
In the following declaration,the array gamma has ____________________ components.
int gamma[5][6][10];
Question
The statement strlen("Marylin Stewart"); returns ____________________.
Question
The following statement creates alpha to be a two-dimensional array with ____________________ rows.
int alpha[10][25];
Question
The function ____________________ returns the length of the string s,excluding the null character.
Question
The ____________________ sort algorithm finds the location of the smallest element in the unsorted portion of the list and moves it to the top of the unsorted portion of the list.
Question
The header file string contains the function ____________________,which converts a value of type string to a null-terminated character array.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 8: Arrays and Strings
1
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
2
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
3
In a two-dimensional array,the elements are arranged in a table form.
True
4
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 << alpha[j] << " ";
Cout << 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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
The one place where C++ allows aggregate operations on arrays is the input and output of C-strings.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
The statement int list[25]; declares list to be an array of 26 components,since the array index starts at 0.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
When you pass an array as a parameter,the base address of the actual array is passed to the formal parameter.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
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.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
All components of an array are of the same data type.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
Suppose that sales is an array of 50 components of type double.Which of the following correctly initializes the array sales?

A) for (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;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
If an array index goes out of bounds,the program always terminates in an error.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
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 << list[j] << " ";
Cout << 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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
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 << list[j] << " ";
Cout << endl;

A) 0 1 2 3 4
B) 0 5 10 15
C) 0 5 10 15 20
D) 5 10 15 20
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
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;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
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 << list[j] << " ";
Cout << endl;
B) for (int j = 0; j <= 9; j++)
Cout << list[j] << " ";
Cout << endl;
C) for (int j = 1; j < 11; j++)
Cout << list[j] << " ";
Cout << endl;
D) for (int j = 1; j <= 10; j++)
Cout << list[j] << " ";
Cout << endl;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
The array index can be any integer less than the array size.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
Arrays can be passed as parameters to a function by value,but it is faster to pass them by reference.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
In a(n)____________________ data type,each data item is a collection of other data items.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following correctly declares and initializes alpha to be an array of four rows and three columns with the component type int?

A) int alpha[4][3] = {{0,1,2} {1,2,3} {2,3,4} {3,4,5}};
B) int alpha[4][3] = {0,1,2; 1,2,3; 2,3,4; 3,4,5};
C) int alpha[4][3] = {0,1,2: 1,2,3: 2,3,4: 3,4,5};
D) int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}};
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
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 fourth column of sale?

A) sum = 0;
For(j = 0; j < 7; j++)
Sum = sum + sale[j][3];
B) sum = 0;
For(j = 0; j < 7; j++)
Sum = sum + sale[j][4];
C) sum = 0;
For(j = 0; j < 10; j++)
Sum = sum + sale[j][4];
D) sum = 0;
For(j = 0; j < 10; j++)
Sum = sum + sale[j][3];
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
In row order form,the ____.

A) first row is stored first
B) first row is stored last
C) first column is stored first
D) first column is stored last
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
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);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
The ____________________ of an array is the address (that is,the memory location)of the first array component.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
In C++,the null character is represented as ____.

A) '\0'
B) "\0"
C) '0'
D) "0"
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
The word ____________________ is used before the array declaration in a function heading to prevent the function from modifying the array.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
Complete the following statement so that it outputs the array sales.
double sales[10];
int index;
for (index = 0; index < 10; index++)
cout << ____________________ << " ";
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following correctly declares name to be a character array and stores "William" in it?

A) char name[6] = "William";
B) char name[7] = "William";
C) char name[8] = "William";
D) char name[8] = 'William';
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
A data type is called ____________________ if variables of that type can store only one value at a time.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
Consider the following declaration: char str[15];.Which of the following statements stores "Blue Sky" into str?

A) str = "Blue Sky";
B) str[15] = "Blue Sky";
C) strcpy(str, "Blue Sky");
D) strcpy("Blue Sky");
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
Consider the following declaration: char charArray[51];
Char discard;
Assume that the input is:
Hello There!
How are you?
What is the value of discard after the following statements execute?
Cin)get(charArray,51);
Cin)get(discard);

A) discard = ' ' (Space)
B) discard = '!'
C) discard = '\n'
D) discard = '\0'
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
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.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Consider the following statement: double alpha[10][5];.The number of components of alpha is ____.

A) 15
B) 50
C) 100
D) 150
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
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.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
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];
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
A collection of a fixed number of elements (called components)arranged in n dimensions (n>=1)is called a(n)____.

A) matrix
B) vector
C) n-dimensional array
D) parallel array
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
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 << gamma[j] << " ";
B) for (j = 1; j < 50; j++)
Cout << gamma[j] << " ";
C) for (j = 0; j <= 50; j++)
Cout << gamma[j] << " ";
D) for (j = 0; j <= 48; j++)
Cout << gamma[j] << " ";
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
The following statements store the value ____________________ into len.
int len;
len = strlen("Sunny California");
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
For a list of length n,the ____________________ sort makes exactly (n(n - 1))/2 key comparisons and 3(n-1)item assignments.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
Two (or more)arrays are called ____________________ if their corresponding components hold related information.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
The declaration char str[] = "Hello there"; declares str to be a string of ____________________ characters.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
In the following declaration,the array gamma has ____________________ components.
int gamma[5][6][10];
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
The statement strlen("Marylin Stewart"); returns ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
The following statement creates alpha to be a two-dimensional array with ____________________ rows.
int alpha[10][25];
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
The function ____________________ returns the length of the string s,excluding the null character.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
The ____________________ sort algorithm finds the location of the smallest element in the unsorted portion of the list and moves it to the top of the unsorted portion of the list.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
The header file string contains the function ____________________,which converts a value of type string to a null-terminated character array.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.