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. This is 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, and your progress syncs across the web and the CoddyKit app. The C Academy course includes 3 lessons in total.
Arrays with Multiple Dimensions
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.

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.
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.
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.
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;
}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]);
}
}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;
}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.
Multidimensional Arrays Recap
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!

Learn C with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 39
- Lessons
- 144
Frequently Asked Questions
Is the “Multidimensional Arrays” lesson free?
Yes — the full text of “Multidimensional Arrays” is free to read here on the web. 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. The C Academy course includes 3 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 3.
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