C Program to Print a 2D Array - Source Code, Output & Execution Flow

C Program to Print a 2D Array

This C program prints all elements of a two-dimensional array.

#include <stdio.h>
int main() {
    int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
    int i, j;
    for (i = 0; i < 2; i++) {
        for (j = 0; j < 3; j++) printf("%d ", a[i][j]);
        printf("
");
    }
    return 0;
}
1 2 3 
4 5 6

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.