C Multidimensional Arrays
1. What is a Multidimensional Array?
-
A multidimensional array is an array of arrays.
-
The most common is a 2D array, which can be thought of as a table with rows and columns.
Syntax for 2D Array:
-
rows→ number of rows -
columns→ number of columns
2. Declaring and Initializing a 2D Array
Declaration Only
Declaration with Initialization
-
Can also initialize in a single line:
3. Accessing Elements in a 2D Array
-
Use row and column indices (both start from 0):
Output:
4. Looping Through a 2D Array
Output:
5. Sum of All Elements in 2D Array
Output:
6. Real-Life Example: Student Marks Table
Output:
Real-life use: Class marks, Excel-like tables, seating arrangements.
7. Key Points About Multidimensional Arrays
-
2D arrays = rows × columns; 3D arrays = tables of matrices.
-
Use nested loops to access all elements.
-
Memory is contiguous, so indexing is efficient.
-
Can initialize row-wise or single line.
-
Avoid accessing indices outside the declared size → undefined behavior.
