### 🔹 Why are vectors used in arrays?
Vectors are used **instead of** arrays when we want more flexibility. A plain array has a **fixed size**, but a vector behaves like a **resizable array**.
So we use vectors when:
- We don’t know how many elements we’ll need in advance
- We want to **add or remove elements easily**
- We want to avoid manually tracking size and shifting elements
---
### 🔹 What is the purpose of vectors?
The purpose of a vector is to make working with sequences of data **easier and safer** than using raw arrays. Vectors provide:
| Feature | Plain Array | Vector (Conceptually) |
|----------------------|---------------------|-------------------------------|
| Fixed size? | Yes | No (can grow/shrink) |
| Easy to add/remove? | No (manual shifting)| Yes (`push_back`, `pop_back`) |
| Tracks size? | No (you track it) | Yes (`size()` is built-in) |
| Safe access? | No bounds checking | Can have bounds checking |
---
### 🔹 In your practice (no STL), what does “vector” mean?
Since you’re not using `std::vector`, you’re **simulating vector behavior** using:
- A fixed-size array (like `int arr[100]`)
- A separate `size` variable
- Functions like:
- `push_back(arr, size, value)`
- `pop_back(arr, size)`
- `insert_at(arr, size, index, value)`
- `erase_at(arr, size, index)`
This helps you understand how real vectors work **under the hood**, and builds strong fundamentals in arrays and functions.
---
### 🔹 Summary
- Vectors are **dynamic arrays** that grow and shrink as needed.
- They are used to make array operations **easier, safer, and more flexible**.
- You can simulate vectors using arrays + functions (like you’re doing now!) to learn the core logic.
