StudyGraph
Procedural Programming with C++ 10 seconds

int scores[10]: what is the last valid index?

Ten seconds. Go. What is the last safe index of scores[10]?

Lesson notes

Declare, initialise and traverse 1D arrays and avoid out-of-bounds access

Key points

Takeaway: Size n means indices 0 to n−1, and C++ never checks bounds.

Quick check: int scores[10]; holds 10 students' marks. What is the largest index you may safely use?
  1. 10
  2. 9
  3. 11

Last valid index = size − 1; loop with i < size, never i <= size.

arrayindexbounds

Lessons like this, for your syllabus.

Short narrated study videos written for your course, level and exam. Free to start.

Get lessons for your own syllabus