Unit 6 Arrays Quiz C#

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Edudzi4k
E
Edudzi4k
Community Contributor
Quizzes Created: 4 | Total Attempts: 3,821
Questions: 20 | Attempts: 1,913

SettingsSettingsSettings
Element Quizzes & Trivia

Questions and Answers
  • 1. 

    In an array, every element has the same .

    • A.

      Subscript

    • B.

      data type

    • C.

      Memory location

    • D.

      all of the above

    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".

    Rate this question:

  • 2. 

    Th e operator used to create objects is .

    • A.

      =

    • B.

      +=

    • C.

      New

    • D.

      Create

    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.

    Rate this question:

  • 3. 

    Which of the following correctly declares an array of four integers?

    • A.

      Int array[4];

    • B.

      Int[] array = 4;

    • C.

      Int[4] array;

    • D.

      Int[] array = new int[4];

    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.

    Rate this question:

  • 4. 

    Th e value placed within square brackets after an array name is .

    • A.

      A subscript

    • B.

      An index

    • C.

      Always an integer

    • D.

      all of these

    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.

    Rate this question:

  • 5. 

    If you defi ne an array to contain seven elements, then the highest array subscript you can use is .

    • A.

      5

    • B.

      6

    • C.

      7

    • D.

      8

    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.

    Rate this question:

  • 6. 

    Initializing an array is in C#.

    • A.

      Required

    • B.

      Optional

    • C.

      Difficult

    • D.

      Prohibited

    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.

    Rate this question:

  • 7. 

    When you declare an array of six double elements but provide no initialization values, the value of the fi rst element is .

    • A.

      0.0

    • B.

      1.0

    • C.

      5.0

    • D.

      Unknown

    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.

    Rate this question:

  • 8. 

    Which of the following correctly declares an array of four integers?

    • A.

      Int[] ages = new int[4] {20, 30, 40, 50};

    • B.

      Int[] ages = new int[] {20, 30, 40, 50};

    • C.

      Int[] ages = {20, 30, 40, 50};

    • D.

      All of these

    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.

    Rate this question:

  • 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 .

    • A.

      0

    • B.

      20

    • C.

      30

    • D.

      Out of bounce

    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.

    Rate this question:

  • 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 .

    • A.

      0

    • B.

      4

    • C.

      50

    • D.

      Out of Balance

    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".

    Rate this question:

  • 11. 

    When you declare an array as int[] temperature = {0, 32, 50, 90, 212, 451};, the value of temperature.Length is .

    • A.

      5

    • B.

      6

    • C.

      7

    • D.

      Unknown

    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.

    Rate this question:

  • 12. 

    Which of the following doubles every value in a ten-element integer array named amount?

    • A.

      For(int x = 9; x >= 0; --x) amount[x] *= 2;

    • B.

      Foreach(int number in amount) number *= 2;

    • C.

      both of these

    • D.

      Neither of these

    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.

    Rate this question:

  • 13. 

    Which of the following adds 10 to every value in a 16-element integer array named points?

    • A.

      For(int sub = 0; sub > 15; ++sub) points[sub] += 10;

    • B.

      Foreach(int sub in points) points += 10;

    • C.

      Both of these

    • D.

      neither of these

    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.

    Rate this question:

  • 14. 

    Two arrays that store related information in corresponding element positions are .

    • A.

      Analogous arrays

    • B.

      Polymorphic arrays

    • C.

      Relative arrays

    • D.

      Parallel arrays

    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.

    Rate this question:

  • 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?

    • A.

      For(int x = 4; x > 0; --x) Console.Write(nums[x]);

    • B.

      For(int x = 3; x >= 0; --x) Console.Write(nums[x]);

    • C.

      For(int x = 3; x > 0; --x) Console.Write(nums[x]);

    • D.

      for(int x = 4; x >= 0; --x) Console.Write(nums[x]);

    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.

    Rate this question:

  • 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?

    • A.

      Array.Sort(nums);

    • B.

      Array.Reverse(nums);

    • C.

      Array.Sort(nums); Array.Reverse(nums);

    • D.

      Array.Reverse(nums); Array.Sort(nums);

    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.

    Rate this question:

  • 17. 

    Which of the following traits do the BinarySearch() and Sort() methods have in common?

    • A.

      Both methods take a single argument that must be an array

    • B.

      Both methods belong to the System.Array class.

    • C.

      Th e array that each method uses must be in ascending order.

    • D.

      They both operate on arrays made up of simple data types but not class objects.

    Correct Answer
    B. Both methods belong to the System.Array class.
    Explanation
    Both the BinarySearch() and Sort() methods belong to the System.Array class.

    Rate this question:

  • 18. 

    If you use the BinarySearch() method and the object you seek is not found in the array, .

    • A.

      An error message is displayed

    • B.

      A zero is returned

    • C.

      The value false is returned

    • D.

      A negative value is returned

    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.

    Rate this question:

  • 19. 

    Which of the following declares an integer array that contains eight rows and fi ve columns?

    • A.

      Int[8, 5] num = new int[ , ];

    • B.

      Int [8][5] num = new int[];

    • C.

      Int [ , ] num = new int[5, 8];

    • D.

      int [ , ] num = new int[8, 5];

    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.

    Rate this question:

  • 20. 

    Th e BinarySearch() method is inadequate when .

    • A.

      array items are in ascending order

    • B.

      The array holds duplicate values and you want to find them all

    • C.

      You want to fi nd an exact match for a value

    • D.

      Array items are not numeric

    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.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 27, 2017
    Quiz Created by
    Edudzi4k
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.