Multidimensional Arrays
Learn about 2D and 3D arrays and how they are used for matrix operations and other complex data structures.
Multidimensional Arrays is a free C Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Multidimensional Arrays
A multidimensional array is an array with more than one dimension, such as a matrix.
In this lesson, you will learn:
- How to declare and initialize 2D and 3D arrays.
- How to access elements in multidimensional arrays.
- How to use nested loops to process multidimensional arrays.

2
Declaring a 2D Array
A 2D array is a table-like structure with rows and columns.
Example declaration:
int matrix[3][3];
This creates a 3×3 integer matrix.
3
Initializing a 2D Array
2D arrays can be initialized using nested curly brackets:
int matrix[2][3] = {
{1, 2, 3},
{4, 5, 6}
};
This creates a 2×3 matrix.
4
Accessing 2D Array Elements
Elements in a 2D array are accessed using row and column indices.
Example:
int value = matrix[1][2];
This retrieves the element in the second row and third column.
5
Example: Accessing 2D Array Elements
This program demonstrates how to store and access values in a 2D array.
#include <stdio.h>
int main() {
int matrix[2][3] = {
{1, 2, 3},
{4, 5, 6}
};
printf("Element at [1][2]: %d\n", matrix[1][2]);
return 0;
}6
Looping Through a 2D Array
We can use nested loops to iterate over a 2D array:
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%d ", matrix[i][j]);
}
}7
Example: Printing a 2D Array
This program prints all elements of a 2D array.
#include <stdio.h>
int main() {
int matrix[2][3] = {
{1, 2, 3},
{4, 5, 6}
};
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
return 0;
}8
9
What is a 3D Array?
A 3D array extends the concept of a 2D array to another dimension.
Example declaration:
int cube[2][3][4];
This creates a 2×3×4 three-dimensional array.
10
Summary
In this lesson, you learned:
- How to declare and initialize 2D arrays.
- How to access and manipulate multidimensional arrays.
- How to use nested loops to process a matrix.
Next, we will explore strings in C!

Frequently asked questions
Is the “Multidimensional Arrays” lesson free?
Yes — the full text of “Multidimensional Arrays” is free to read here on the web, and the C Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO.
What will I learn in “Multidimensional Arrays”?
Learn about 2D and 3D arrays and how they are used for matrix operations and other complex data structures. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C Academy?
No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Multidimensional Arrays” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C Academy lesson?
Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Arrays
- Multidimensional Arrays
- Strings in C