std::array & C-arrays in C++
From the C++ cheat sheet · Arrays & Vectors · verified Jul 2026
std::array & C-arrays
Fixed-size sequences.
cpp
// Quick Reference
#include <array>
std::array<int, 3> a = {1, 2, 3};
a.size(); a[0];
int c[3] = {1, 2, 3}; // C-style💡 Prefer std::array over C arrays - it carries its size and works with range-for and algorithms.
⚡ A C array decays to a pointer when passed to a function, losing its length.
📌 std::array size is a compile-time constant; std::vector when the size varies at runtime.
🟢 std::array lives on the stack (no heap allocation) - fast for small fixed collections.
arrayc-array