Add Two 4D Arrays Dry Run in C

Add Two 4D Arrays is an interactive C dry run visualizer from the Multi D programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Add Two 4D Arrays Program Code

#include <stdio.h>
int main() {
    int A[2][2][2][2], B[2][2][2][2], C[2][2][2][2], i, j, k, l;
    
    for(i =0;i<2;i++) for(j =0;j<2;j++)
        for(k =0;k<2;k++) for(l =0;l<2;l++) {
            A[i][j][k][l] = i*1000 + j*100 + k*10 + l;
            B[i][j][k][l] = l*1000 + k*100 + j*10 + i;
            C[i][j][k][l] = A[i][j][k][l] + B[i][j][k][l];
        }
    
    printf("C array after addition:\n");
    for(i =0;i<2;i++) {
        printf("Layer %d:\n", i);
        for(j =0;j<2;j++) {
            printf("Row %d: ", j);
            for(k =0;k<2;k++) {
                for(l =0;l<2;l++) {
                    printf("%d ", C[i][j][k][l]);
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

View the complete Multi D programs page.

Program Console Add Two 4D Arrays Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.