📅 Date: Jan 13, 2026
🔥 Topic: 2D Arrays (Matrices)
⬛ Rows and Columns
Sometimes data isn't a straight line; it's a grid (like a Chessboard or an Excel sheet). For this, we use 2D Arrays.
Syntax: int arr[rows][columns];
Visualizing arr[2][3]:
[ 0, 0 ] [ 0, 1 ] [ 0, 2 ]
[ 1, 0 ] [ 1, 1 ] [ 1, 2 ]
💻 Day 13 Code: Hardcoded Matrix
#include <iostream>
using namespace std;
int main() {
// Declaration: 3 Rows, 3 Cols
int grid[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
// Accessing specific element (Row 1, Col 2)
// Remember index starts at 0!
cout << "Element at [1][2] is: " << grid[1][2] << endl;
// Output should be 6
return 0;
}
💭 Thoughts
It's basically an "Array of Arrays". To handle this, I will need Nested Loops (a loop inside a loop) tomorrow.
No comments:
Post a Comment