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_...
very nice! You are moving well. ** Day 7 ** On a specific ** c ++ course **, you will usually cover:
,
## ✅ ** Multi -time arrays (2D arrays) **
### 🔹 1. ** Introduction to 2D arrays **
A 2D array is like a table - ** with rows and columns **.
`` `CPP
#INCLUDE <iostream>
using namespace std;
int main() {
Int matrix [2] [3] = {
{1, 2, 3},
{4, 5, 4}
,
// Row 1, access element on column 2
cout << Matrix [1] [2]; // Output: 6
Return 0;
,
,
,
### 🔹 2. ** Input and output in a 2D array **
`` `CPP
int main() {
Int Arr [2] [3];
// input
For (int i = 0; i <2; i ++) {
For (int j = 0; j <3; j ++) {
Cout << "Enter the element [" << I << "] [" << j << "]:";
CIN >> arrest [i] [j];
,
,
// Output
cout << "\ Nmatrix: \ n";
For (int i = 0; i <2; i ++) {
For (int j = 0; j <3; j ++) {
cout << arr [i] [j] << "";
,
cout << endl;
,
Return 0;
,
,
,
### 🔹 3. ** Matrix Add **
`` `CPP
int main() {
int a [2] [2] = {{{{1, 2}, {3, 4}};
int b [2] [2] = {{5, 4}, {7, 8}};
int sum [2] [2];
For (int i = 0; i <2; i ++) {
For (int j = 0; j <2; j ++) {
sum [i] [j] = a [i] [j] + b [i] [j];
,
,
// print yoga
For (int i = 0; i <2; i ++) {
For (int j = 0; j <2; j ++) {
cout << sum [i] [j] << "" ";
,
cout << endl;
,
Return 0;
,
,
,
### 🔹 4. ** Transport of a matrix **
`` `CPP
int main() {
int a [2] [3] = {{{1, 2, 3}, {4, 5, 6}}};
INT transposose [3] [2];
For (int i = 0; i <2; i ++) {
For (int j = 0; j <3; j ++) {
Transport [j] [i] = a [i] [j];
,
,
// print transposose
For (int i = 0; i <3; i ++) {
For (int j = 0; j <2; j ++
Comments
Post a Comment