Guided Notes

Arrays & Vectors

Built-in arrays and std::array, std::vector and its operations, iterating, sorting with std::sort, and 2D data.

Arrays

Slide 1 / 5

A built-in array has a fixed size set at compile time: int scores[5] = {90, 78, 85, 92, 67}; scores[0] is 90; scores[4] is 67.

• Indexes run from 0 to size āˆ’ 1. • Out-of-range access isn't checked — it's undefined behavior. • std::array<int, 5> (from <array>) is the modern version: it knows its size (.size()), can be copied, and offers .at(i) with bounds checking.

For most code, prefer std::vector.

← Loops