Published 2026-11-28
std::array has a fixed size known when you write the code. std::vector can grow and shrink while the program runs.
Rule of thumb: use std::vector by default. Use std::array when the size never changes, like the 7 days of a week.
Both know their own size(), work with range-based for loops and can be passed to STL algorithms — much safer than old C-style arrays.
#include <array>
#include <vector>
std::array<int, 3> fixed{1, 2, 3};
std::vector<int> grow{1, 2};
grow.push_back(3);