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]?
Quick check · tap an answer to continue
Lesson notes
Declare, initialise and traverse 1D arrays and avoid out-of-bounds access
Key points
- Arrays in C++ are indexed from 0, so the ten elements are scores[0] to scores[9].
- scores[10] is out of bounds, and C++ will not stop you, so the loop must use i < 10.
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?
- 10
- 9
- 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