C Tutorial — Learn C Programming
Key takeaway: This free C tutorial teaches you systems programming from scratch — variables, pointers, arrays, functions, structs, and memory management — with practical code examples you can compile and run.
C is a general-purpose, procedural programming language created in 1972. It is used for operating systems, embedded systems, game engines, and performance-critical applications. This tutorial is for beginners, CS students, and developers who want to understand how computers work at a low level.
Last updated: September 2026
Multidimensional Arrays in C
Multidimensional arrays are arrays of arrays. The most common type is the 2D array, which can be visualized as a table with rows and columns.
2D Array Declaration
#include <stdio.h>
int main() {
// 2D array declaration and initialization
int matrix[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
printf("Matrix:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
// Calculate sum of diagonal elements
int diagonalSum = 0;
for (int i = 0; i < 3; i++) {
diagonalSum += matrix[i][i];
}
printf("Sum of diagonal elements: %d\n", diagonalSum);
return 0;
}Matrix Operations
#include <stdio.h>
int main() {
int matrix1[2][2] = {{1, 2}, {3, 4}};
int matrix2[2][2] = {{5, 6}, {7, 8}};
int result[2][2];
// Matrix addition
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
result[i][j] = matrix1[i][j] + matrix2[i][j];
}
}
printf("Matrix 1:\n");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
printf("%d ", matrix1[i][j]);
}
printf("\n");
}
printf("\nMatrix 2:\n");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
printf("%d ", matrix2[i][j]);
}
printf("\n");
}
printf("\nSum:\n");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
printf("%d ", result[i][j]);
}
printf("\n");
}
return 0;
}