1. Given a one dimensional array arr, what is the correct way of getting the number of elements in arr. Select the one correct answer.
  1. a. arr.length

  2. b. arr.length - 1

  3. c. arr.size

  4. d. arr.size - 1

  5. e. arr.length()


Correct Option: A

AI Explanation

To answer this question, you need to understand how to determine the number of elements in a one-dimensional array.

Option A) arr.length - This option is correct. In most programming languages, the length property is used to find the number of elements in an array. Therefore, arr.length will give you the correct number of elements in the array.

Option B) arr.length - 1 - This option is incorrect. Subtracting 1 from arr.length would give you the index of the last element in the array, not the number of elements in the array.

Option C) arr.size - This option is incorrect. The size property is not commonly used to find the number of elements in an array.

Option D) arr.size - 1 - This option is incorrect for the same reason as Option B. Subtracting 1 from arr.size would give you the index of the last element, not the number of elements.

Option E) arr.length() - This option is incorrect. In most programming languages, length() is not a valid method for finding the number of elements in an array. The correct property is length without parentheses.

The correct answer is Option A) arr.length. This option is correct because it provides the appropriate property to determine the number of elements in the array.

Find more quizzes: