📘 Lesson  ·  Lesson 75

Vectors and Maps

Vectors and Maps

Vector and Map

💡 Note

vector is a dynamic array (grows automatically). map stores sorted key-value pairs.

Vector

C++
#include <vector>
vector<int> v;
v.push_back(10);
v.push_back(20);
cout << v[0] << " " << v.size();   // 10 2
Output:
10 2

Map

C++
#include <map>
map<string,int> m;
m["Aman"] = 88;
m["Riya"] = 92;
cout << m["Aman"];   // 88
Output:
88

Summary

  • vector = resizable array with push_back, size, [].
  • map = key-value store, automatically sorted by key.

Vector और Map

💡 Note

vector dynamic array है (अपने आप बढ़ता है)। map sorted key-value pairs रखता है।

Vector

C++
#include <vector>
vector<int> v;
v.push_back(10);
v.push_back(20);
cout << v[0] << " " << v.size();   // 10 2
Output:
10 2

Map

C++
#include <map>
map<string,int> m;
m["Aman"] = 88;
m["Riya"] = 92;
cout << m["Aman"];   // 88
Output:
88

सारांश

  • vector = push_back, size, [] वाला resizable array।
  • map = key-value store, key से अपने आप sorted।
← Back to C++ Tutorial
🔗

Share this topic with a friend

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

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

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

\n