Program Console Vignaankosh.com
Execution Panel
Console is empty.
Dynamic array of structures 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.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Course {
int courseId;
char name[50];
int credits;
};
void addCourse(struct Course **courses, int *count, int id, char name[], int credits) {
*courses = (struct Course*)realloc(*courses, (*count + 1) * sizeof(struct Course));
if(*courses != NULL) {
(*courses)[*count].courseId = id;
strcpy((*courses)[*count].name, name);
(*courses)[*count].credits = credits;
(*count)++;
printf("Course added: %s\n", name);
}
}
void displayCourses(struct Course *courses, int count) {
printf("\n--- Course List ---\n");
printf("%-10s %-30s %-10s\n", "ID", "Course Name", "Credits");
printf("----------------------------------------\n");
for(int i = 0; i < count; i++) {
printf("%-10d %-30s %-10d\n",
courses[i].courseId, courses[i].name, courses[i].credits);
}
}
int main() {
struct Course *courses = NULL;
int count = 0;
addCourse(&courses, &count, 101, "C Programming", 4);
addCourse(&courses, &count, 102, "Data Structures", 4);
addCourse(&courses, &count, 103, "Database Systems", 3);
addCourse(&courses, &count, 104, "Operating Systems", 3);
displayCourses(courses, count);
printf("\nTotal Credits: ");
int totalCredits = 0;
for(int i = 0; i < count; i++) {
totalCredits += courses[i].credits;
}
printf("%d\n", totalCredits);
free(courses);
return 0;
}