🔴 Advanced · Lesson 54
Vector in C++ STL
Vector in C++ STL
What is Vector in C++ STL?
Vector in C++ STL
A vector is a dynamic array that can grow or shrink at runtime. It supports fast indexing and easy insertion at the end.
A vector is a dynamic array that can grow or shrink at runtime. It supports fast indexing and easy insertion at the end.
Level
🔴 STL, Modern C++ and Projects
🔴 STL, Modern C++ and Projects
Example File
vector.cppMain Focus
Concept + syntax + practical C++ program
Concept + syntax + practical C++ program
Why should you learn this?
- It helps you write correct and readable C++ programs.
- It is used repeatedly in school practicals, projects and competitive programming.
- It builds the base for advanced topics such as OOP, STL and data structures.
Important Terms
| Term | Meaning / Use |
|---|---|
| vector | Vector in C++ STL programming में Vector use होता है। |
| push_back | Vector in C++ STL programming में Push_back use होता है। |
| size | Vector in C++ STL programming में Size use होता है। |
| index | Vector in C++ STL programming में Index use होता है। |
| dynamic array | Vector in C++ STL programming में Dynamic array use होता है। |
Syntax / Pattern
C++
vector<int> v; v.push_back(value);
Example Program
main.cpp
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> marks;
marks.push_back(90);
marks.push_back(85);
cout << marks.size();
}Expected Output
2
Program Explanation
- push_back adds values at the end.
- size() returns number of elements.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.
Where will you use it?
- marks list
- dynamic records
- algorithm practice
Common Mistakes
- Accessing invalid index.
- Using vector without #include <vector>.
Practice Tasks
- Store five marks in vector and find total.
- Remove last element using pop_back().
Summary
Vector in C++ STL एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।
Vector in C++ STL क्या है?
Vector in C++ STL
A vector is a dynamic array that can grow or shrink at runtime. It supports fast indexing and easy insertion at the end.
A vector is a dynamic array that can grow or shrink at runtime. It supports fast indexing and easy insertion at the end.
Level
🔴 STL, Modern C++ and Projects
🔴 STL, Modern C++ and Projects
Example File
vector.cppमुख्य फोकस
Concept + syntax + practical C++ program
Concept + syntax + practical C++ program
इसे क्यों सीखें?
- यह आपको सही और पढ़ने-योग्य C++ programs लिखने में मदद करता है।
- यह school practicals, projects और competitive programming में बार-बार use होता है।
- यह OOP, STL और data structures जैसे advanced topics की नींव बनाता है।
ज़रूरी Terms
| Term | अर्थ / उपयोग |
|---|---|
| vector | Vector Vector in C++ STL programming में use होता है। |
| push_back | Push_back Vector in C++ STL programming में use होता है। |
| size | Size Vector in C++ STL programming में use होता है। |
| index | Index Vector in C++ STL programming में use होता है। |
| dynamic array | Dynamic array Vector in C++ STL programming में use होता है। |
Syntax / Pattern
C++
vector<int> v; v.push_back(value);
Example Program
main.cpp
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> marks;
marks.push_back(90);
marks.push_back(85);
cout << marks.size();
}Expected Output
2
Program Explanation
- push_back adds values at the end.
- size() returns number of elements.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.
Where will you use it?
- marks list
- dynamic records
- algorithm practice
आम गलतियाँ (Common Mistakes)
- Accessing invalid index.
- Using vector without #include <vector>.
अभ्यास (Practice Tasks)
- Store five marks in vector and find total.
- Remove last element using pop_back().
सारांश
Vector in C++ STL एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.