Dynamic Arrays with std::vector

🟡 Intermediate

📖 Definition

Provided in <vector>, std::vector<T> is a dynamic array class that automatically manages contiguous heap memory, resizing itself as elements are inserted or erased.

💡 Code Example

#include <iostream>
#include <vector>

int main() {
    std::vector<int> vec;
    vec.push_back(100);
    vec.push_back(200);
    vec.push_back(300);

    for (int x : vec) {
        std::cout << x << " ";
    }
    std::cout << "\n";
    return 0;
}