TryBugHunt

C++ vector exercises

std::vector is the workhorse of C++, but standard indexing with [] does no bounds checking, leading to silent memory corruption or segmentation faults. Pushing elements into a vector can reallocate storage and invalidate active iterators or pointers.

These exercises give you deliberate practice identifying container defects before they cause production crashes.

See the 17 exercisesOr follow the 30-day path

The vectors bugs you will meet

The exercises

Errors you might be searching for

More JavaScript practice by topic

Questions

Why does vector [] access not throw an exception?

C++ prioritizes raw performance; operator[] is unchecked. Use .at() if you want bounds checking with std::out_of_range exceptions.