Initialize array at time of declaration (Different methods) Dry Run in C

Initialize array at time of declaration (Different methods) is an interactive C dry run visualizer from the Arrays 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.

Initialize array at time of declaration (Different methods) Program Code

#include <stdio.h>
int main() {
    // Method 1: Full initialization
    int arr1[5] = {1, 2, 3, 4, 5}, i;
    
    // Method 2: Partial initialization (remaining become 0)
    int arr2[5] = {1, 2, 3};
    
    // Method 3: Size omitted (compiler determines size)
    int arr3[] = {10, 20, 30, 40};
    
    // Method 4: Initialize all to zero
    int arr4[5] = {0};
    
    for(i = 0; i < 5; i++)
        printf("%d ", arr1[i]);
    printf("\n");
    
    for(i = 0; i < 5; i++)
        printf("%d ", arr2[i]);
    printf("\n");
    
    for(i = 0; i < 4; i++)
        printf("%d ", arr3[i]);
    
    return 0;
}

View the complete Arrays programs page.

Program Console Initialize array at time of declaration (Different methods) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.