Pass array of structures to function Dry Run in C

Pass array of structures to function is an interactive C dry run visualizer from the Struct Functions Pointers 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.

Pass array of structures to function Program Code

#include <stdio.h>

struct Student {
    int roll;
    char name[50];
    float marks;
};

void displayAll(struct Student arr[], int size) {
    printf("\n--- All Students ---\n");
    for(int i = 0; i < size; i++) {
        printf("%d. Roll: %d, Name: %s, Marks: %.2f\n", 
               i+1, arr[i].roll, arr[i].name, arr[i].marks);
    }
}

float calculateAverage(struct Student arr[], int size) {
    float sum = 0;
    for(int i = 0; i < size; i++) {
        sum += arr[i].marks;
    }
    return sum / size;
}

int main() {
    struct Student students[3] = {
        {101, "Alice", 85.5},
        {102, "Bob", 78.0},
        {103, "Charlie", 92.5}
    };
    
    displayAll(students, 3);
    printf("\nAverage Marks: %.2f\n", calculateAverage(students, 3));
    return 0;
}

View the complete Struct Functions Pointers programs page.

Program Console Pass array of structures to function Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.