Deck 7: Arrays
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/48
Play
Full screen (f)
Deck 7: Arrays
1
Write the declaration for a function named funct1 that expects an array of floats, the number of elements in the array and does not return any value.
void funct1float myArray[], int numElements);
2
The following array declaration is legal
double scores[]={0.1,0.2,0.3};
double scores[]={0.1,0.2,0.3};
True
3
The modifier that guarantees that an array argument will not be changed is called ______.
const
4
If your index used to access the indexed variables of the array has the value of a non-existent index, this is called _________
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
5
How many indexed variables does the following array have?
int myArray[12]={1,2,3,6,5,4,7,1,2};
int myArray[12]={1,2,3,6,5,4,7,1,2};
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
6
The following function declaration guarantees the values in the array argument are not changed.
void function1int array[], int numElements);
void function1int array[], int numElements);
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
7
If you use the const modifier in a function declaration, you do not include it in the function definition.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
8
Write the code to declare a two dimension array of integers with 10 rows and 20 columns.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
9
The locations of the various indexed variables in an array can be spread out all over the memory.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
10
Write the code to declare an array of 10 doubles named list;
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
11
How many indexed variables does the following array have?
int myArray[]={1,2,3,6,5,4,7,1,2};
int myArray[]={1,2,3,6,5,4,7,1,2};
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
12
Arrays can be passed to functions.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
13
If you put a value in the square brackets of a one-dimension array parameter, this value is _________ by the compiler.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
14
The computer remembers the address of which indexed variables) in an array? ______
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
15
A computer's memory consists of numbered locations called __________.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
16
Arrays can be returned from a function.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
17
If a function is expecting a pass by reference parameter, you can pass an index variable from an array of the same base type to that function.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
18
The following function will work with any size integer array.
void function1int array[], int numElements);
void function1int array[], int numElements);
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
19
The indexed variables members) of an array must be integers.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
20
When you have a function that expects an array, it should also expect the size of the array or the number of indexed variables with valid data.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
21
What is wrong with the following code fragment?
Const int SIZE =5;
Float scores[SIZE];
Forint i=0; i<=SIZE;i++)
{
Cout << "Enter a score\n";
Cin >> scores[i];
}
A) Array indexes start at 1 not 0
B) Arrays must be integers
C) Array indexes must be less than the size of the array
D) Should be cin >> scores[0];
Const int SIZE =5;
Float scores[SIZE];
Forint i=0; i<=SIZE;i++)
{
Cout << "Enter a score\n";
Cin >> scores[i];
}
A) Array indexes start at 1 not 0
B) Arrays must be integers
C) Array indexes must be less than the size of the array
D) Should be cin >> scores[0];
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
22
What are the valid indexes for the array shown below?
Int myArray[25];
A) 0-25
B) 0-24
C) 1-25
D) 1-24
Int myArray[25];
A) 0-25
B) 0-24
C) 1-25
D) 1-24
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
23
Given the following function definition, will repeated calls to the search function for the same target find all occurrences of that target in the array?
Int searchconst int array[], int target, int numElements)
{
Int index=0;
Bool found=false;
While!found) && index < numElements))
{
Ifarray[index] == target)
Found=true;
Else
Index++;
}
Iffound==true)
Return index;
Else
Return -1;
}
A) Yes
B) No
C) Impossible to tell without looking at the values of the array
D) It depends on the value of target.
Int searchconst int array[], int target, int numElements)
{
Int index=0;
Bool found=false;
While!found) && index < numElements))
{
Ifarray[index] == target)
Found=true;
Else
Index++;
}
Iffound==true)
Return index;
Else
Return -1;
}
A) Yes
B) No
C) Impossible to tell without looking at the values of the array
D) It depends on the value of target.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
24
If we want a search function to search an array for some value and return either the index where the value was found, or -1 if not found, which of the following prototypes would be appropriate?
A) void searchconst int array, int target, int numElements);
B) void searchconst int array, int target);
C) int searchconst int array[], int numElements);
D) int searchconst int array[], int target, int numElements);
A) void searchconst int array, int target, int numElements);
B) void searchconst int array, int target);
C) int searchconst int array[], int numElements);
D) int searchconst int array[], int target, int numElements);
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
25
In the expression
double score[10];
double is called the ___________ of the array
double score[10];
double is called the ___________ of the array
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
26
Given an array of integers of size 5, how does the computer know where the 3rd indexed variable is located?
A) It adds 3 to the base address of the array
B) It adds space for 3 integers to the base address of the array
C) It remembers where all the indexed variables of the array are located.
D) None of the above
A) It adds 3 to the base address of the array
B) It adds space for 3 integers to the base address of the array
C) It remembers where all the indexed variables of the array are located.
D) None of the above
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
27
Given the following function definition for a search function, and the following variable declarations, which of the following are appropriate function invocations?
Const int SIZE=1000;
Int searchconst int array[], int target, int numElements);
Int array[SIZE], target, numberOfElements;
A) searcharray[0], target, numberOfElements);
B) result=searcharray[0], target, numberOfElements);
C) result=searcharray, target, numberOfElements);
D) result=searcharray, target, SIZE);
Const int SIZE=1000;
Int searchconst int array[], int target, int numElements);
Int array[SIZE], target, numberOfElements;
A) searcharray[0], target, numberOfElements);
B) result=searcharray[0], target, numberOfElements);
C) result=searcharray, target, numberOfElements);
D) result=searcharray, target, SIZE);
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
28
In the expression
cout << score[i] << endl;
i is called the
cout << score[i] << endl;
i is called the
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
29
An _______ is used to process a collection of data all of which is the same type
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
30
Given the following function definition, what modifications need to be made to the search function so that it finds all occurrences of target in the array?
Int searchconst int array[], int target, int numElements)
{
Int index=0;
Bool found=false;
While!found) && index < numElements))
{
Ifarray[index] == target)
Found=true;
Else
Index++;
}
Iffound==true)
Return index;
Else
Return -1;
}
A) Add another parameter to indicate where to stop searching
B) Add another parameter to indicate where to start searching
C) This already can find all occurrences of a given target
D) Have the function return the whole array
Int searchconst int array[], int target, int numElements)
{
Int index=0;
Bool found=false;
While!found) && index < numElements))
{
Ifarray[index] == target)
Found=true;
Else
Index++;
}
Iffound==true)
Return index;
Else
Return -1;
}
A) Add another parameter to indicate where to stop searching
B) Add another parameter to indicate where to start searching
C) This already can find all occurrences of a given target
D) Have the function return the whole array
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following function declarations correctly guarantee that the function will not change any values in the array argument?
A) void f1int array[], int size) const;
B) void f1int array[], int size);
C) void f1int &array, int size);
D) void f1const int array[], int size);
E) void f1int array[], const int size);
A) void f1int array[], int size) const;
B) void f1int array[], int size);
C) void f1int &array, int size);
D) void f1const int array[], int size);
E) void f1int array[], const int size);
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
32
Given an array named scores with 25 elements, what is the correct way to access the 25th element?
A) scores+25
B) scores[24]
C) scores[25]
D) scores[last]
A) scores+25
B) scores[24]
C) scores[25]
D) scores[last]
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
33
Arrays are always passed to a function using
A) pass by value
B) pass by reference
C) pass by array
D) you cannot pass arrays to a function
A) pass by value
B) pass by reference
C) pass by array
D) you cannot pass arrays to a function
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
34
Indexes are numbered starting at _________
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following function declarations could be used to input data from the keyboard into the array?
A) void inputint array[], int &numElements, int MAX_SIZE);
B) void inputint array[], int numElements, int MAX_SIZE);
C) void inputint &array[], int numElements, int MAX_SIZE);
D) int array[] inputint array[], int &numElements, int MAX_SIZE);
A) void inputint array[], int &numElements, int MAX_SIZE);
B) void inputint array[], int numElements, int MAX_SIZE);
C) void inputint &array[], int numElements, int MAX_SIZE);
D) int array[] inputint array[], int &numElements, int MAX_SIZE);
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
36
Which sort algorithm does the following outline define?
For i between 0 and number_used-1 inclusive
Put the ith smallest element at array[i]
A) sequential
B) selection
C) bubble
D) swap
For i between 0 and number_used-1 inclusive
Put the ith smallest element at array[i]
A) sequential
B) selection
C) bubble
D) swap
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
37
The individual variables that comprise an array are called __________
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
38
What is wrong with the following code?
Float scores[10], total;
A) Cannot declare regular and array variables together.
B) Arrays must be integers
C) The 10 should be replaced with a variable name, whose value is input from the user
D) Nothing.
Float scores[10], total;
A) Cannot declare regular and array variables together.
B) Arrays must be integers
C) The 10 should be replaced with a variable name, whose value is input from the user
D) Nothing.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
39
Why should you use a named constant for the size of an array?
A) Readability of code
B) Makes changes to the program easier
C) Helps reduce logic errors
D) All of the above
A) Readability of code
B) Makes changes to the program easier
C) Helps reduce logic errors
D) All of the above
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
40
If you declare and initialize an integer array of size 10, but only list 5 values, what values are stored in the remaining 5 indexed variables?
A) 0
B) garbage
C) 0.0
D) '0'
A) 0
B) garbage
C) 0.0
D) '0'
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
41
If you need a function that will handle multi-dimensional arrays, you must specify the following sizes inside the square brackets.
A) All the sizes
B) All sizes except the last dimension
C) All sizes except the first dimension
D) None of the sizes
A) All the sizes
B) All sizes except the last dimension
C) All sizes except the first dimension
D) None of the sizes
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
42
Which of the following correctly uses C++11's range-based for statement to iterate through every element of the array variable arr?
A) for auto x : arr)
B) foreach x in arr)
C) for auto x; x < arr.length; x++)
D) for x in arr
A) for auto x : arr)
B) foreach x in arr)
C) for auto x; x < arr.length; x++)
D) for x in arr
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following will correctly assign all the values in one array to the other array? Assume both arrays are of the same type and have SIZE elements)
A) array1=array2;
B) array1[]=array2;
C) fori=0;iD) fori=0;i
A) array1=array2;
B) array1[]=array2;
C) fori=0;i
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
44
What is the output of this code?
Int arr[] = { 1, 2, 3};
For int &element : arr)
Element+=10;
For int element : arr)
Cout << element << endl;
A) 1 2 3
B) 11 12 13
Int arr[] = { 1, 2, 3};
For int &element : arr)
Element+=10;
For int element : arr)
Cout << element << endl;
A) 1 2 3
B) 11 12 13
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
45
Which of the following will read values from the keyboard into the array? Assume the size of the array is SIZE).
A) cin >> array;
B) cin >> array[];
C) cin >> array[SIZE];
D) fori=0;i> array[i];
A) cin >> array;
B) cin >> array[];
C) cin >> array[SIZE];
D) fori=0;i
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following function declarations will accept the following two-dimension array?
Int pages[10][30];
A) void f1int pages[][], int size);
B) void f1int pages[][30], int size);
C) void f1int pages[10][], int size);
D) void f1int& pages, int size);
Int pages[10][30];
A) void f1int pages[][], int size);
B) void f1int pages[][30], int size);
C) void f1int pages[10][], int size);
D) void f1int& pages, int size);
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
47
What is the output of this code?
Int arr[] = { 1, 2, 3};
For int element : arr)
Element+=10;
For int element : arr)
Cout << element << endl;
A) 1 2 3
B) 11 12 13
Int arr[] = { 1, 2, 3};
For int element : arr)
Element+=10;
For int element : arr)
Cout << element << endl;
A) 1 2 3
B) 11 12 13
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
48
Which of the following correctly declare an array that can hold up to 3 rows of 5 columns of doubles?
A) int array[3],[5];
B) int array[3][5];
C) float array[3][5];
D) float array[3,5];
A) int array[3],[5];
B) int array[3][5];
C) float array[3][5];
D) float array[3,5];
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck