Array inside structure (marks, subjects) Dry Run in C

Array inside structure (marks, subjects) 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 inside structure (marks, subjects) Program Code

#include <stdio.h>

#define NUM_SUBJECTS 5

struct StudentRecord {
    int rollNumber;
    char studentName[40];
    int marks[NUM_SUBJECTS];
    char subjectNames[NUM_SUBJECTS][30];
};

int main() {
    struct StudentRecord sr = {
        201,
        "Kavita Nair",
        {88, 76, 94, 82, 89},
        {"Mathematics", "Physics", "Chemistry", "Biology", "English"}
    };
    
    int total = 0;
    int i;
    printf("Student: %s (Roll: %d)\n", sr.studentName, sr.rollNumber);
    printf("\n%-20s %s\n", "Subject", "Marks");
    printf("%-20s %s\n", "-------", "-----");
    
    for(i = 0; i < NUM_SUBJECTS; i++) {
        printf("%-20s %d\n", sr.subjectNames[i], sr.marks[i]);
        total += sr.marks[i];
    }
    
    printf("\nTotal Marks: %d\n", total);
    printf("Percentage: %.2f%%\n", (float)total / NUM_SUBJECTS);
    
    return 0;
}

View the complete Structures programs page.

Program Console Array inside structure (marks, subjects) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.