A multidimensional array is an array with more than one dimension. The most
commonly used multidimensional arrays are two-dimensional arrays, which are
organized in rows and columns. Such arrays are useful for representing tables,
matrices, and other structured data.

Elements of a multidimensional array are accessed using multiple subscripts, one
for each dimension. Storage of multidimensional arrays follows a row-major order
in C.
SYNTAX:

datatype array_name[rows][columns];
EXAMPLE:

#include <stdio.h>

int main() {
        int batch[2][3] = {
        {240, 250, 260},
        {245, 255, 265} 
    };

   
    printf("Weight of Tin 1 in Batch 0: %d\n", batch[0][1]);

    
    printf("Weight of Tin 2 in Batch 1: %d\n", batch[1][2]);

    return 0;
}
EXAMPLE:

#include <stdio.h>

int main() {
    int batch[2][3] = {
        {240, 250, 260}, 
        {245, 255, 265}
    };

    for (int i = 0; i < 2; i++) { 
        for (int j = 0; j < 3; j++) { 
            printf("%d  ", batch[i][j]); 
        }
        printf("\n");
    }

    return 0;
}
Previous Next