Array of structures Dry Run in C

Array of structures is an interactive C dry run visualizer from the Structures 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.

Array of structures Program Code

#include <stdio.h>

struct Employee {
    int id;
    char name[40];
    float salary;
};

int main() {
    // Array of 5 Employee structures
    struct Employee company[5] = {
        {101, "Rajesh Kumar", 45000.00},
        {102, "Priya Singh", 52000.00},
        {103, "Amit Patel", 48000.00},
        {104, "Neha Gupta", 55000.00},
        {105, "Suresh Nair", 47000.00}
    };
    int i;
    float totalSalary = 0;
    
    printf("--- Employee Directory ---\n");
    printf("%-6s %-20s %10s\n", "ID", "Name", "Salary");
    printf("%-6s %-20s %10s\n", "--", "----", "------");
    
    // Access each element of the array
    for(i = 0; i < 5; i++) {
        printf("%-6d %-20s Rs.%9.2f\n", 
               company[i].id, 
               company[i].name, 
               company[i].salary);
    }
    
    // Calculate total salary expense
    for(i = 0; i < 5; i++) {
        totalSalary += company[i].salary;
    }
    printf("\nTotal Monthly Salary Expense: Rs.%.2f\n", totalSalary);
    printf("Average Salary: Rs.%.2f\n", totalSalary / 5);
    
    return 0;
}

View the complete Structures programs page.

Program Console Array of structures Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.