Caffeinated Coder
Book an appointment
Lesson 11 · Memory

Undefined behaviour: one read past the end

Some mistakes in C++ are not errors at all in the eyes of the language: the standard simply stops saying what happens. Follow an eight-line program whose loop reads one element past the end of an array. It compiles without a warning, nothing checks the read, and the result is undefined. Then see why optimisers make it worse, how AddressSanitizer catches it, and how to fix it.

11 min10 steps5 questionsIntermediate
Fig 11 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.