🔶 1. Definition & Concept

vector ek dynamic array hai jo C++ STL (Standard Template Library) ka part hai.

🔹 Normal arrays me size fix hota hai — once declared, badal nahi sakta.

🔹 vector me aap run-time par size increase/decrease kar sakte ho.


vector<int> v; // empty vector of integers

🧠 Think of vector like:


[ 1, 2, 3 ] → push_back(4) → [ 1, 2, 3, 4 ]


🔶 2. Header & Syntax


#include <vector>     // Required header
using namespace std;

vector<int> v;        // Declaration


🔶 3. Initialization Methods

Syntax Description
vector<int> v; Empty vector
vector<int> v(5); Size 5, default values (0)
vector<int> v(5, 10); 5 elements, all 10
vector<int> v = {1,2,3}; List initialization
vector<int> v2(v); Copy constructor

🔶 4. Common Functions with Example

✅ push_back()


v.push_back(10); // [10]
v.push_back(20); // [10, 20]

✅ pop_back()