Array: initializing and using three dimensional arrays

supriyo_biswas · updated April 11, 2020
#include <stdio.h>

int main() {
    // declare a 3x2x2 3D array with initializer list
    int a[3][2][2] = {
        {
            {10, 20},
            {30, 40},
        },
        {
            {1, 2},
            {4, 5}
        },
        {
            {3, 5},
            {7, 11}
        }
    };

    // declare loop variable
    int i, j, k;

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

    return 0;
}
Output
(Run the program to view its output)

Comments

Please sign up or log in to contribute to the discussion.