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. 24 — ConceptIn 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.…
- A.
26
- B.
25
- C.
24
- 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
Let N = 25, the number of elements.
Use the last-index rule: N - 1.
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.