🔴 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.
Level
🔴 STL, Modern C++ and Projects
Example File
vector.cpp
Main Focus
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

TermMeaning / Use
vectorVector in C++ STL programming में Vector use होता है।
push_backVector in C++ STL programming में Push_back use होता है।
sizeVector in C++ STL programming में Size use होता है।
indexVector in C++ STL programming में Index use होता है।
dynamic arrayVector 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

  1. Store five marks in vector and find total.
  2. 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.
Level
🔴 STL, Modern C++ and Projects
Example File
vector.cpp
मुख्य फोकस
Concept + syntax + practical C++ program

इसे क्यों सीखें?

  • यह आपको सही और पढ़ने-योग्य C++ programs लिखने में मदद करता है।
  • यह school practicals, projects और competitive programming में बार-बार use होता है।
  • यह OOP, STL और data structures जैसे advanced topics की नींव बनाता है।

ज़रूरी Terms

Termअर्थ / उपयोग
vectorVector Vector in C++ STL programming में use होता है।
push_backPush_back Vector in C++ STL programming में use होता है।
sizeSize Vector in C++ STL programming में use होता है।
indexIndex Vector in C++ STL programming में use होता है।
dynamic arrayDynamic 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)

  1. Store five marks in vector and find total.
  2. Remove last element using pop_back().

सारांश

Vector in C++ STL एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।

← Back to C++ Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n

💻 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ें.