0Pricing
C++ Academy · Lesson

Vector vs std::array vs C Array

Compare the three sequential containers and pick one based on size, ownership, and performance.

Three Sequential Containers

C++ has three ways to hold a contiguous sequence:

  • std::vector — dynamic size, heap storage
  • std::array — fixed size at compile time, stack storage
  • C-style array — fixed size, low level

C-Style Arrays

The oldest form. Size is part of the type. Decays to a pointer when passed to functions — losing the size.

int a[5] = {1, 2, 3, 4, 5};
std::cout << a[2];   // 3

All lessons in this course

  1. std::vector Basics: push_back size capacity
  2. Iterating Vectors: index range-for iterators
  3. Modifying Vectors: insert erase clear
  4. Vector vs std::array vs C Array
← Back to C++ Academy