Multidimensional Arrays
Learn about multidimensional arrays that are very useful for solving programming problems.
We'll cover the following...
C provides support for multidimensional arrays. Here is how we can define a two-dimensional array of integers, initialize values, and index into it to read off values:
Press + to interact
#include <stdio.h>int main(void){int grades[2][2] = {1, 2, 3, 4};int i, j;for (i = 0; i < 2; i++) {for (j = 0; j < 2; j++) {printf("grades[%d][%d]=%d\n", i, j, grades[i][j]);}}return 0;}
We can think of this array as a matrix or a table with 2 rows and 2 columns:
- The first row contains