Mastering C++
Dynamic 2D Arrays (Matrices)
Mastering PointersSometimes we need to store data in a grid, not just a list. A 2D array lets us organize data in rows and columns, like a game board or a table. But if the size of the array can change while the program runs, we need to create it dynamically using pointers.
Creating the 2D Array
To create a 2D array, we need to use a double pointer, written as int**. A double pointer allows us to create a grid which is an array of rows, where each row is its own array of integers.
Members only
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 21 more lessons in Mastering C++.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.