1.
In an array, every element has the same .
Correct Answer
B. data type
Explanation
In an array, every element must have the same data type. This means that all elements in the array should be of the same type, such as integers, characters, or floating-point numbers. Having elements with different data types would result in an inconsistent and unpredictable behavior when accessing and manipulating the array. Therefore, the correct answer is "data type".
2.
Th e operator used to create objects is .
Correct Answer
C. New
Explanation
The operator "new" is used to create objects in programming. It is commonly used in object-oriented languages like Java and C++. When "new" is used, memory is allocated for the object and its constructor is called to initialize its state. This allows us to create instances of classes and use their methods and properties. Therefore, "new" is the correct operator to create objects.
3.
Which of the following correctly declares an array of four integers?
Correct Answer
D. Int[] array = new int[4];
Explanation
The correct answer is "int[] array = new int[4];". This statement correctly declares an array of four integers. It uses the "new" keyword to allocate memory for the array and specifies the size of the array as 4. The "int[]" part declares the variable as an array of integers.
4.
Th e value placed within square brackets after an array name is .
Correct Answer
D. all of these
Explanation
The value placed within square brackets after an array name is referred to as a subscript or an index. It is used to access a specific element within the array. The subscript or index is typically an integer, but it can also be any other data type as long as it can be converted to an integer. Therefore, the correct answer is "all of these" as all the options mentioned are valid explanations for the value placed within square brackets after an array name.
5.
If you defi ne an array to contain seven elements, then the highest array subscript you can use is .
Correct Answer
B. 6
Explanation
When defining an array to contain seven elements, the array subscript starts from 0 and goes up to the size of the array minus one. In this case, the array has seven elements, so the highest array subscript that can be used is 6.
6.
Initializing an array is in C#.
Correct Answer
B. Optional
Explanation
In C#, initializing an array is optional. It means that you have the choice to initialize an array when declaring it or you can leave it uninitialized. If you choose not to initialize the array, the elements will be assigned their default values based on their data types. However, if you want to explicitly assign values to the elements of the array during declaration, you can do so using the initializer syntax.
7.
When you declare an array of six double elements but provide no initialization values, the value of the fi rst element is .
Correct Answer
A. 0.0
Explanation
When you declare an array of double elements without providing any initialization values, the default value for each element is 0.0. Therefore, the value of the first element in the array will be 0.0.
8.
Which of the following correctly declares an array of four integers?
Correct Answer
D. All of these
Explanation
All of the given options correctly declare an array of four integers. In the first option, the size of the array is explicitly mentioned as 4, and the values are initialized within curly braces. In the second option, the size of the array is not mentioned, but it is automatically determined based on the number of values provided within the curly braces. The third option is a shorthand syntax where the size of the array is again automatically determined based on the number of values provided. Therefore, all of these options correctly declare an array of four integers.
9.
When an ages array is correctly initialized using the values {20, 30, 40, 50}, as in Question 8, then the value of ages[1] is .
Correct Answer
C. 30
Explanation
The correct answer is 30 because the array index starts from 0, so ages[1] refers to the second element in the array, which is 30.
10.
When an ages array is correctly initialized using the values {20, 30, 40, 50}, as in Question 8, then the value of ages[4] is .
Correct Answer
D. Out of Balance
Explanation
The given question states that the ages array is correctly initialized using the values {20, 30, 40, 50}. However, the question asks for the value of ages[4], which is out of the bounds of the array. Since arrays are zero-indexed, the last index in this case would be ages[3]. Therefore, there is no value for ages[4], and the answer is "Out of Balance".
11.
When you declare an array as int[] temperature = {0, 32, 50, 90, 212, 451};, the value of temperature.Length is .
Correct Answer
B. 6
Explanation
When you declare an array as int[] temperature = {0, 32, 50, 90, 212, 451};, the value of temperature.Length is 6. This is because the array has 6 elements in it, each separated by a comma and enclosed within curly braces. The .Length property in C# returns the number of elements in an array, so in this case, it would return 6.
12.
Which of the following doubles every value in a ten-element integer array named amount?
Correct Answer
A. For(int x = 9; x >= 0; --x) amount[x] *= 2;
Explanation
The correct answer is "for(int x = 9; x >= 0; --x) amount[x] *= 2;". This is the correct answer because it uses a for loop to iterate through each element of the array "amount" starting from the last element and going to the first element. It then multiplies each element by 2, effectively doubling its value.
13.
Which of the following adds 10 to every value in a 16-element integer array named points?
Correct Answer
D. neither of these
Explanation
The given correct answer is "neither of these". This is because both of the options provided in the question do not correctly add 10 to every value in the array.
In the first option, the for loop condition is incorrect. It should be "sub < 15" instead of "sub > 15" to iterate through all the elements of the array.
In the second option, the foreach loop is used incorrectly. Instead of adding 10 to each element of the array, it is trying to add 10 to the entire array, which is not possible.
Therefore, neither of these options correctly adds 10 to every value in the array.
14.
Two arrays that store related information in corresponding element positions are .
Correct Answer
D. Parallel arrays
Explanation
Parallel arrays are two arrays that store related information in corresponding element positions. Each element in one array corresponds to the element at the same position in the other array. This allows for easy retrieval of related data by accessing elements at the same index in both arrays. For example, if one array stores names and the other array stores ages, the name and age of a person can be accessed by using the same index position in both arrays.
15.
Assume an array is defi ned as int[] nums = {2, 3, 4, 5};. Which of the following would display the values in the array in reverse?
Correct Answer
B. For(int x = 3; x >= 0; --x) Console.Write(nums[x]);
Explanation
The correct answer is the fourth option: for(int x = 4; x >= 0; --x) Console.Write(nums[x]). This loop starts at the last index of the array (4) and iterates backwards until it reaches the first index (0). It uses the decrement operator (--x) to move from one index to the previous one. The Console.Write(nums[x]) statement prints the value at each index, resulting in the values of the array being displayed in reverse order.
16.
Assume an array is defi ned as int[] nums = {7, 15, 23, 5};. Which of the following would place the values in the array in descending numeric order?
Correct Answer
C. Array.Sort(nums); Array.Reverse(nums);
Explanation
The correct answer is "Array.Sort(nums); Array.Reverse(nums);". This is because the Array.Sort(nums) method will sort the values in the array in ascending order, and then the Array.Reverse(nums) method will reverse the order of the sorted array, resulting in the values being in descending numeric order.
17.
Which of the following traits do the BinarySearch() and Sort() methods have in common?
Correct Answer
B. Both methods belong to the System.Array class.
Explanation
Both the BinarySearch() and Sort() methods belong to the System.Array class.
18.
If you use the BinarySearch() method and the object you seek is not found in the array, .
Correct Answer
D. A negative value is returned
Explanation
When using the BinarySearch() method, if the object being sought is not found in the array, a negative value is returned. This negative value indicates the index at which the object would be inserted into the array to maintain the sorted order. This allows the user to determine the appropriate position for the object if they want to insert it into the array.
19.
Which of the following declares an integer array that contains eight rows and fi ve columns?
Correct Answer
D. int [ , ] num = new int[8, 5];
Explanation
The correct answer is "int [ , ] num = new int[8, 5];". This statement declares an integer array named "num" with eight rows and five columns. The syntax "new int[8, 5]" specifies the dimensions of the array. The square brackets indicate that it is a multidimensional array, and the numbers inside represent the size of each dimension.
20.
Th e BinarySearch() method is inadequate when .
Correct Answer
B. The array holds duplicate values and you want to find
them all
Explanation
The BinarySearch() method is inadequate when the array holds duplicate values and you want to find them all. This is because the BinarySearch() method is designed to find a single occurrence of a value in a sorted array. It uses a divide and conquer approach, repeatedly dividing the array in half until the target value is found or determined to not be present. In the case of duplicate values, the BinarySearch() method may not correctly identify all occurrences of the value, as it may stop searching after finding the first occurrence. To find all duplicate values in an array, a different approach or method would be needed.