Skip to main content

Types of Arrays in C

Arrays in C are classified by their number of dimensions — how many indices are needed to access an element.

1. One-Dimensional Array (1D)

The simplest array — stores elements in a single row. One index is enough to access any element. Syntax:
Example:

2. Two-Dimensional Array (2D)

Stores elements in rows and columns — like a matrix or table. Two indices are needed: [row][column]. Syntax:
Example:
Output:
Memory layout of matrix[2][3]:

3. Multi-Dimensional Array

Has more than two dimensions. Think of it as an array of 2D arrays. Used for complex data structures like 3D matrices or cubic grids. Syntax of a 3D array:
Example:
Output:

Comparison