O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing Past the End of an Array

When you reference an element in an array, the compiler (unfortunately) does not care whether the element actually exists. It computes how far past the first element it should go and then generates instructions that get or change that location's content. If the element is past the bounds of the array, this can be virtually anything and the results will be unpredictable. If you're lucky, your program will crash immediately or throw a bounds violation exception. If you're unlucky, you may get strange results much further on in your program run. You need to make sure that the condition in your for statement will cause the loop to stop before it goes past the bounds of the array. The condition expression Index <

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required