In zero-based array indexing, what is the index of the last element in an…

2019

In zero-based array indexing, what is the index of the last element in an array containing 25 elements?

Answer: C. 24ConceptIn zero-based indexing, the first element is stored at index 0. For an array containing N elements, valid indices therefore run from 0 through N - 1.…

  1. A.

    26

  2. B.

    25

  3. C.

    24

  4. D.

    23

Attempted by 258 students.

Show answer & explanation

Correct answer: C

Concept

In zero-based indexing, the first element is stored at index 0. For an array containing N elements, valid indices therefore run from 0 through N - 1.

Thus, the last index is obtained by subtracting 1 from the number of elements.

Application

  1. Let N = 25, the number of elements.

  2. Use the last-index rule: N - 1.

  3. Substitute N = 25: 25 - 1 = 24.

Cross-check

Counting from index 0 through index 24 gives 25 positions in total, so index 24 is the last valid index.

Therefore, the index of the last element is 24.

Explore the full course: Up Police Computer Operator

Loading lesson…