A segmentation fault occurs when a user program attempts to do one of :
- Access a part of the memory it is not allowed to, such as system memory
- Access a part of the memory which does not exist (aka out of bounds)
So you are correct in realizing that you are reaching out of bounds in your array, and on the last loop iteration you are accessing something outside of your program's allocated memory. It just so happens that the piece of memory is not system memory and it exists, so it lets you read it.
If you ran this bit of code enough times you should eventually get a segmentation fault because it will happen to be placed right up against system memory or at the end of memory.