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
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/75
Play
Full screen (f)
Deck 7: Arrays
1
For an array that is dimensioned with a Length of 100,valid subscripts are 0 through 100.
False
2
When an array is sent to a method as an argument,if the method changes one or more of the elements,the changes are made to the actual data.
True
3
To declare an array,the value(s)used inside the square bracket can be a constant literal,a variable,or an expression that produces an integral value.
True
4
A parallel array is used to create string arrays because multiple characters are included within each element.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
5
Arrays can be used as fields or instance variables in classes;and,arrays of objects can be declared.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
6
If you use the params parameter type,params must appear both in the formal parameter list of the method heading and in the actual argument list.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
7
In C# the length of an array cannot be changed.After it is instantiated with a length,dynamic resizing is not an option.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
8
The type used in the foreach expression must match the array type.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
9
double [ ] price = new double [ ] {3, 2.2, 4.7, 6.1, 4};
With the declaration above,price[5] generates a runtime error.
With the declaration above,price[5] generates a runtime error.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
10
double [ ] price = new double [ ] {3, 2.2, 4.7, 6.1, 4};
With the declaration above,price[2] refers to 2.2.
With the declaration above,price[2] refers to 2.2.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
11
Because arrays are reference types,the ref keyword is required with the argument and parameter list.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
12
Arrays are reference variables.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
13
When a method uses the params modifier,it indicates that the number of arguments to the method may vary.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
14
Arrays can be sent to methods as arguments,and methods can have arrays as their return type.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
15
Properties are added to a class to enable client applications to access public members.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
16
Array identifiers are normally defined using a plural noun.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
17
The Clear( )method of the Array class sets all integer elements to zero.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
18
double [ ] price = new double [ ] {3, 2.2, 4.7, 6.1, 4};
Looking above,the value of price.Length is 5.
Looking above,the value of price.Length is 5.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
19
You can declare an array without dimensioning its size,but the size must be determined before you can access it.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
20
When you pass an array to a method,by default,a copy of each element in the array is made and passed to the method.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
21
With parallel arrays,the relationship is established through using the same subscript or index to refer to the elements in both arrays.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
22
All arrays are objects of the base type ____ class.
A) Object
B) Base
C) Super
D) Array
A) Object
B) Base
C) Super
D) Array
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
23
The index is also referred to as the ____ of the array.
A) value
B) element
C) size
D) subscript
A) value
B) element
C) size
D) subscript
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
24
int [ ] anArray = new int[24];
Array elements are normally stored in contiguous,side-by-side,memory locations with the first index in all arrays being referenced by index 0.
Array elements are normally stored in contiguous,side-by-side,memory locations with the first index in all arrays being referenced by index 0.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
25
There are several ways to do a compile-time initialization of arrays.All of the following are valid ways EXCEPT ____.
A) int [ ] anArray = {100, 100, 100};
B) int [ ] anArray = new int [ ] {100, 100, 100};
C) int [ ] anArray = new int [3 ] {100, 100, 100};
D) int [ ] anArray = new int [10 ] {100, 100, 100};
A) int [ ] anArray = {100, 100, 100};
B) int [ ] anArray = new int [ ] {100, 100, 100};
C) int [ ] anArray = new int [3 ] {100, 100, 100};
D) int [ ] anArray = new int [10 ] {100, 100, 100};
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
26
int [ ] anArray = new int[24];
For the above declaration,25 cells are set aside for the array since the first element is referenced by index 0.
For the above declaration,25 cells are set aside for the array since the first element is referenced by index 0.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
27
All arrays are objects of the base type Array class.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
28
If an array named num is dimensioned to hold 10 values,how would you store 50 in the 5th physical location?
A) num[5] = 50;
B) num[4] = 50;
C) num = 50 [5] ;
D) num5 = 50;
A) num[5] = 50;
B) num[4] = 50;
C) num = 50 [5] ;
D) num5 = 50;
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
29
When you pass a single array element such as an integer,you are passing by reference.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
30
int [ ] anArray = new int[24];
You can instantiate arrays of user-defined array objects and send in arrays as arguments to methods,but you cannot return arrays from methods.
You can instantiate arrays of user-defined array objects and send in arrays as arguments to methods,but you cannot return arrays from methods.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
31
You create an array in much the same way you instantiate an object of a user-defined class,by using the new keyword at the time of declaration.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
32
When you use the assignment operator with an array,individual elements are copied to another memory location.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
33
To declare and instantiate memory for 4 exam scores that range in value from 0 to 100,the following declaration could be made ____.
A) int examScore = new examScore[3];
B) int [ ] examScore = new examScore[4];
C) int [ ] examScore = new examScore[3];
D) int examScore[4] = new examScore[ ];
A) int examScore = new examScore[3];
B) int [ ] examScore = new examScore[4];
C) int [ ] examScore = new examScore[3];
D) int examScore[4] = new examScore[ ];
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
34
Use .NET predefined methods and properties whenever possible as opposed to writing new
code.
code.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
35
If an array named num is dimensioned to hold 10 values,what happens if you write num[100] = 50;?
A) A compilation error will be generated
B) A runtime error will be generated
C) 50 will be stored at the 100th indexed location
D) 50 will be stored at the last legal location
A) A compilation error will be generated
B) A runtime error will be generated
C) 50 will be stored at the 100th indexed location
D) 50 will be stored at the last legal location
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
36
int [ ] anArray = new int[24];
Array identifiers are normally defined using a plural noun.
Array identifiers are normally defined using a plural noun.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
37
Given an array declared to hold 100 values,the smallest index that can be used with the array is ____.
A) based on what index is used when the first value is placed in the array
B) 1
C) 0
D) undetermined
A) based on what index is used when the first value is placed in the array
B) 1
C) 0
D) undetermined
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
38
If you do not know how many entries will be stored with the array,you could dimension it ____.
A) small and then as more space is needed, adjust its size
B) large enough to hold the most likely number of entries
C) large enough to hold the maximum number of entries
D) as zero length and then add one to the length each time you add a value
A) small and then as more space is needed, adjust its size
B) large enough to hold the most likely number of entries
C) large enough to hold the maximum number of entries
D) as zero length and then add one to the length each time you add a value
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
39
If you try to access the array using a negative index value,____.
A) a compilation error will be generate
B) a runtime error will be generated
C) the indexed location will be used. The computer will access memory to the left of the array
D) the smallest indexed location will be accessed
A) a compilation error will be generate
B) a runtime error will be generated
C) the indexed location will be used. The computer will access memory to the left of the array
D) the smallest indexed location will be accessed
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
40
Given an array declared to hold 100 values,the largest index that can be used with the array is:
A) based on what index is used when the first value is placed in the array
B) 99
C) 100
D) undetermined
A) based on what index is used when the first value is placed in the array
B) 99
C) 100
D) undetermined
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
41
int [ ] anArray = new int [10];
int [ ] anotherArray = {6, 7, 4, 5, 6, 2, 3, 5, 9, 1};
Which of the following would copy all of the elements from anotherArray to anArray?
A) Array.Copy(anotherArray, 0, anArray, 0, 10);
B) Array.Copy(anotherArray, anArray)
C) anArray = anotherArray
D) all of the above
int [ ] anotherArray = {6, 7, 4, 5, 6, 2, 3, 5, 9, 1};
Which of the following would copy all of the elements from anotherArray to anArray?
A) Array.Copy(anotherArray, 0, anArray, 0, 10);
B) Array.Copy(anotherArray, anArray)
C) anArray = anotherArray
D) all of the above
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
42
When two or more arrays have a relationship such that you are able to use the same subscript or index to refer to related elements in the arrays,you have ____ arrays.
A) parallel
B) two dimensional
C) dynamic
D) related
A) parallel
B) two dimensional
C) dynamic
D) related
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
43
What happens when you assign one array to another using the assignment operator?
A) An error message is generated.
B) Elements are copied to new memory locations.
C) Both arrays become value type data elements.
D) Both arrays reference the same memory locations.
A) An error message is generated.
B) Elements are copied to new memory locations.
C) Both arrays become value type data elements.
D) Both arrays reference the same memory locations.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
44
One of the special properties in the Array class is Length.It returns ____.
A) an int representing the number of values currently stored in the array
B) an int representing the size the array was dimensioned
C) how much storage is consumed by the entire array
D) the length of an individual element of the array
A) an int representing the number of values currently stored in the array
B) an int representing the size the array was dimensioned
C) how much storage is consumed by the entire array
D) the length of an individual element of the array
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
45
int [ ] anArray = new int [10];
int [ ] anotherArray = {6, 7, 4, 5, 6, 2, 3, 5, 9, 1};
anotherArray.Length returns ____.
A) 9
B) 10
C) 11
D) 20
int [ ] anotherArray = {6, 7, 4, 5, 6, 2, 3, 5, 9, 1};
anotherArray.Length returns ____.
A) 9
B) 10
C) 11
D) 20
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following could be a method heading for a member method that returns an array?
A) int [ ] void DoSomething( )
B) void int [ ] DoSomething( )
C) int [ ] DoSomething( )
D) void DoSomething[ ]
A) int [ ] void DoSomething( )
B) void int [ ] DoSomething( )
C) int [ ] DoSomething( )
D) void DoSomething[ ]
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
47
int [ ] anArray = new int [10];
int [ ] anotherArray = {6, 7, 4, 5, 6, 2, 3, 5, 9, 1};
How could all values of anotherArray be totaled?
A) foreach(int val in anotherArray)
Total += val;
B) for (int i = 0; i < anotherArray.Length; i++)
Total += anotherArray;
C) Array.Sum(anotherArray)
D) all of the above
int [ ] anotherArray = {6, 7, 4, 5, 6, 2, 3, 5, 9, 1};
How could all values of anotherArray be totaled?
A) foreach(int val in anotherArray)
Total += val;
B) for (int i = 0; i < anotherArray.Length; i++)
Total += anotherArray;
C) Array.Sum(anotherArray)
D) all of the above
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
48
A limitation of the foreach loop structure when used with arrays is ____.
A) it offers read only access
B) it can only be used with integer arrays
C) a loop control variable must be defined on the outside of the loop
D) the control variable must be updated with each iteration
A) it offers read only access
B) it can only be used with integer arrays
C) a loop control variable must be defined on the outside of the loop
D) the control variable must be updated with each iteration
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
49
Given an array declaration of int anArray[1000],which of the following would be a valid heading for a method that sends the array in as a parameter?
A) void DisplayContents(int anArray)
B) void DisplayContents(int anArray[])
C) void DisplayContents(int [ ] anArray)
D) void DisplayContents(anArray[1000])
A) void DisplayContents(int anArray)
B) void DisplayContents(int anArray[])
C) void DisplayContents(int [ ] anArray)
D) void DisplayContents(anArray[1000])
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
50
If an array is to be sent to a method,which of the following is a valid heading for a method?
A) void DisplayOutput(double [ ] anArray)
B) void DisplayOutput(double [10 ] anArray)
C) void DisplayOutput(double anArray)
D) void DisplayOutput(double anArray [10])
A) void DisplayOutput(double [ ] anArray)
B) void DisplayOutput(double [10 ] anArray)
C) void DisplayOutput(double anArray)
D) void DisplayOutput(double anArray [10])
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
51
Which of the following can be used to return an index of an item in an array?
A) LastIndexOf( )
B) Index( )
C) Find( )
D) SetValue( )
A) LastIndexOf( )
B) Index( )
C) Find( )
D) SetValue( )
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
52
____ creates a copy of the array and returns it as an object?
A) CopyObject( )
B) Clone( )
C) Copy( )
D) CreateArray( )
A) CopyObject( )
B) Clone( )
C) Copy( )
D) CreateArray( )
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
53
foreach (int val in anotherArray) total += val;
Using the above declaration along with the foreach loop,what is stored in total after the program statements are executed?
A) 10
B) 2
C) 48
D) 45
Using the above declaration along with the foreach loop,what is stored in total after the program statements are executed?
A) 10
B) 2
C) 48
D) 45
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
54
int [ ] score = {86,66,76,92,95,88}; for (int i = score.Length-1;i > -1;i--)
{
Total += score[i];
}
Using the declaration above for score,what is added to total during the first iteration?
A) 0
B) 88
C) 86, 66, 76, 92 and 95
D) unknown, because i is not initialized
{
Total += score[i];
}
Using the declaration above for score,what is added to total during the first iteration?
A) 0
B) 88
C) 86, 66, 76, 92 and 95
D) unknown, because i is not initialized
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
55
Given an array declaration of int anArray[1000],which of the following would be a valid call to a DisplayContents( )method to send the full array into the method as an argument?
A) DisplayContents(int anArray[1000])
B) DisplayContents(anArray[1000])
C) DisplayContents(anArray[ ] )
D) DisplayContents(anArray)
A) DisplayContents(int anArray[1000])
B) DisplayContents(anArray[1000])
C) DisplayContents(anArray[ ] )
D) DisplayContents(anArray)
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
56
for (int i = 0;i < anotherArray.Length;i++) total += i;
Using the above declaration along with the for loop,what is stored in total after the program statements are executed?
A) 10
B) 2
C) 48
D) 45
Using the above declaration along with the for loop,what is stored in total after the program statements are executed?
A) 10
B) 2
C) 48
D) 45
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
57
Which loop structure can be used to change the contents of the array?
A) for
B) foreach
C) loop
D) if / else
A) for
B) foreach
C) loop
D) if / else
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
58
BinarySearch( )is ____.
A) a method in the Array class
B) an instance method
C) usable as long as you declare an array
D) must be used with integer arguments
A) a method in the Array class
B) an instance method
C) usable as long as you declare an array
D) must be used with integer arguments
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
59
Which of the following is a valid example of calling a method and sending it an array argument?
A) DisplayArrayContents(int [ ] anArray);
B) DisplayArrayContents(anArray);
C) DisplayArrayContents(anArray[10]);
D) DisplayArrayContents(int [ 10] anArray);
A) DisplayArrayContents(int [ ] anArray);
B) DisplayArrayContents(anArray);
C) DisplayArrayContents(anArray[10]);
D) DisplayArrayContents(int [ 10] anArray);
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
60
If you do not know the size of the array needed,you can create an array large enough to hold any number of entries and tell users to enter a predetermined sentinel value after they enter the last value.Using this approach:
A) requires that you increment a counter as values are entered so that you know how many elements are stored in your array
B) is preferred to defining a static sized array.
C) requires that you dimension the array to hold at least 100 entries.
D) requires the array be defined to hold string elements.
A) requires that you increment a counter as values are entered so that you know how many elements are stored in your array
B) is preferred to defining a static sized array.
C) requires that you dimension the array to hold at least 100 entries.
D) requires the array be defined to hold string elements.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
61
The length or size of the array is specified using a(n)____________ value in the form of a constant literal,a variable,or an expression that produces an integer value.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
62
To create an array to hold the 5 numeric scores,you could write ____________.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
63
One of the special properties in the Array class is ____________.It returns an int representing the total number of elements in an array.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
64
All data values placed in an array must be of the same ____________.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
65
An entire array collection of data can be ordered alphabetically with a call to the Array class member method ____________.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
66
Elements in an array are sometimes referred to as ____________ variables.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
67
Array.Copy(waterDepth, 2, w, 0, 5);
The Copy( )method,shown above,is a(n)____________ method.
The Copy( )method,shown above,is a(n)____________ method.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
68
All arrays,of any type,inherit characteristics from the ____________ class,which includes a number of predefined methods and properties.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
69
Use the ____________ keyword to instantiate an object of an array.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
70
Array identifiers are normally defined using a ____________.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
71
The ____________ loop structure can be used to iterate through an array.However,it can be used for read-only access to the elements.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
72
When you do a compile-time initialization of array elements,values are separated by ____________.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
73
The first element of an array is always referenced by index ____________.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
74
Arrays are ____________ variables.The array identifier memory location does not actually contain the values,but instead stores an address indicating the location of the first element in the array.
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck
75
To access an array element,you must specify which element is to be retrieved by placing an index inside ____________ following the array identifier
Unlock Deck
Unlock for access to all 75 flashcards in this deck.
Unlock Deck
k this deck