Dynamic structure variable using pointer Dry Run in C

Dynamic structure variable using pointer 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.

Dynamic structure variable using pointer Program Code

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

struct Song {
    char title[100];
    char artist[50];
    int duration;  // in seconds
};

int main() {
    // Dynamically allocate memory for one structure
    struct Song *songPtr = (struct Song*)malloc(sizeof(struct Song));
    
    if(songPtr == NULL) {
        printf("Memory allocation failed!\n");
        return 1;
    }
    
    // Initialize using pointer
    strcpy(songPtr->title, "Bohemian Rhapsody");
    strcpy(songPtr->artist, "Queen");
    songPtr->duration = 355;
    
    printf("Dynamic Song Record:\n");
    printf("Title: %s\n", songPtr->title);
    printf("Artist: %s\n", songPtr->artist);
    printf("Duration: %d seconds (%d:%02d)\n", 
           songPtr->duration, songPtr->duration/60, songPtr->duration%60);
    
    // Free allocated memory
    free(songPtr);
    songPtr = NULL;
    
    return 0;
}

View the complete Struct Functions Pointers programs page.

Program Console Dynamic structure variable using pointer Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.