C++ Day 39 STL Containers (Deep Understanding & Real Usage) Till now, you already know arrays, vectors, loops, and STL algorithms. Today, we go one step deeper and understand STL containers , which are the backbone of modern C++ programming. In real projects and competitive coding, choice of container matters a lot. 1. What are STL Containers? STL containers are data structures provided by C++ to store data efficiently. They handle: memory management resizing element access performance optimization You focus on logic , not memory handling. 2. Categories of STL Containers STL containers are mainly divided into: Sequence Containers Associative Containers Unordered Containers Container Adapters 3. Sequence Containers These store data in sequence . 3.1 Vector Most used container in C++. vector< int > v; Key Features: Dynamic size Contiguous memory Fast random access Slower insertion in middle Example: v. push_...
Fabulous Often 6 days of C ++ course are addressed:
Angians are fine in C ++.
Arrays save several values of the same type under a variable.
,
1. What is an array?
A collection of array elements, stored in embodied memory sites.
,
#INCLUDE <iostream>
using namespace std;
int main()
INT Number [5] = {10, 20, 30, 40, 50};
// Elements access
cout << "first element:" << number [0] << Endl;
Return zero;
,
,
,
## 2. Using input and output arrays
`` `CPP
int main()
Int Marx [5];
// input
For (int i = 0; i <5)
cout << i+1 << ":"; Enter the mark;
Cin marks [i];
,
// Output
cout << recorded marks:
For (int i = 0; i <5; i ++) {
Cout << "Mark" << i+1 << ":" << Marks [i] << Endl;
,
Return 0;
,
,
,
3. Array
,
Int Arr1 [4] = {1, 2, 3, 4}; // All the members initialized
Int Arr2 [5] = {1, 2};
,
,
4. Find maximum elements in an array
`` `CPP
int main()
Int Nums [] = {12, 45, 23, 67, 34};
Int maximum = nums [0];
For (int i = 1; i <5; i ++) {
If nums [i]> maximum,
Maximum = nums [i];
,
,
cout << "maximum:" << maximum << endl;
Return 0;
,
,
,
## 5. Array elements
,
int main() {
Int Arr [] = {5, 10, 15, 20};
Int sum = 0;
For (int i = 0; i <4; i ++) {
Sum += arr [i];
,
cout << endl; Cout << "Sum =" << Sum
Return 0.
,
,
,
### ๐ exercise questions
1. Find the meaning of ten number input by the user.
2. Identify the smallest number in an array.
3. Determine the number of even and odd numbers.
4. Rotate the components of an array.
,
Do you want 2D arrays (usually presented next) or help with any of these exercise practice solutions?
Comments
Post a Comment