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]; // 3All lessons in this course
- std::vector Basics: push_back size capacity
- Iterating Vectors: index range-for iterators
- Modifying Vectors: insert erase clear
- Vector vs std::array vs C Array