Array of pointers to structures Dry Run in C

Array of pointers to 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.

Array of pointers to structures Program Code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

int main() {
    struct Student *students[5];  // Array of 5 pointers
    int n = 3;  // Number of students to create
    
    // Dynamically create students
    for(int i = 0; i < n; i++) {
        students[i] = (struct Student*)malloc(sizeof(struct Student));
        
        if(students[i] != NULL) {
            students[i]->roll = 101 + i;
            sprintf(students[i]->name, "Student_%d", i+1);
            students[i]->cgpa = 7.5 + (i * 0.5);
        }
    }
    
    // Display using the array of pointers
    printf("Students (using array of pointers):\n");
    for(int i = 0; i < n; i++) {
        printf("Roll: %d, Name: %s, CGPA: %.1f\n", 
               students[i]->roll, students[i]->name, students[i]->cgpa);
    }
    
    // Free memory
    for(int i = 0; i < n; i++) {
        free(students[i]);
    }
    
    return 0;
}

View the complete Struct Functions Pointers programs page.

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