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:2. Two-Dimensional Array (2D)
Stores elements in rows and columns — like a matrix or table. Two indices are needed:[row][column].
Syntax:
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:Comparison
| Type | Indices | Access | Use Case |
|---|---|---|---|
| 1D | 1 | arr[i] | List of values |
| 2D | 2 | arr[i][j] | Tables, matrices |
| 3D | 3 | arr[i][j][k] | 3D grids |