Skip to content
techsnow

Functions & Arrays

Vectors

A vector is a dynamic array that can grow and shrink. It is the most used container in C++.

#include <vector>
#include <algorithm>

vector<int> marks = {85, 92, 78};
marks.push_back(88);                 // add to the end
marks.pop_back();                    // remove the last
cout << marks.size() << endl;        // 3

sort(marks.begin(), marks.end());    // 78 85 92
for (int m : marks) cout << m << " ";

Output

3
78 85 92