Pass structure pointer to function Dry Run in C

Pass structure pointer 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 structure pointer to function Program Code

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

struct Book {
    int id;
    char title[100];
    char author[50];
    float price;
};

void inputBook(struct Book *b) {
    printf("Enter Book ID: ");
    scanf("%d", &b->id);
    printf("Enter Title: ");
    scanf(" %[^\n]", b->title);
    printf("Enter Author: ");
    scanf(" %[^\n]", b->author);
    printf("Enter Price: ");
    scanf("%f", &b->price);
}

void displayBook(struct Book *b) {
    printf("\n--- Book Details ---\n");
    printf("ID: %d\n", b->id);
    printf("Title: %s\n", b->title);
    printf("Author: %s\n", b->author);
    printf("Price: ₹%.2f\n", b->price);
}

void applyDiscount(struct Book *b, float percent) {
    float discount = b->price * percent / 100;
    b->price -= discount;
    printf("Discount applied: %.1f%% (₹%.2f)\n", percent, discount);
}

int main() {
    struct Book myBook;
    
    printf("Enter Book Information:\n");
    inputBook(&myBook);
    
    displayBook(&myBook);
    
    applyDiscount(&myBook, 15);
    printf("Price after discount: ₹%.2f\n", myBook.price);
    
    return 0;
}

View the complete Struct Functions Pointers programs page.

Program Console Pass structure pointer to function Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.