📘 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
10 2
Map
C++
#include <map> map<string,int> m; m["Aman"] = 88; m["Riya"] = 92; cout << m["Aman"]; // 88
Output:
88
88
Summary
- vector = resizable array with push_back, size, [].
- map = key-value store, automatically sorted by key.
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
10 2
Map
C++
#include <map> map<string,int> m; m["Aman"] = 88; m["Riya"] = 92; cout << m["Aman"]; // 88
Output:
88
88
सारांश
- vector = resizable array with push_back, size, [].
- map = key-value store, automatically sorted by key.
💻 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ें.