Update structure values Dry Run in C

Update structure values 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.

Update structure values Program Code

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

struct Product {
    int id;
    char name[50];
    float price;
    int quantity;
};

void updatePrice(struct Product *p, float newPrice) {
    p->price = newPrice;  // Arrow operator for pointer
}

void updateQuantity(struct Product *p, int newQty) {
    p->quantity = newQty;
}

int main() {
    struct Product prod = {101, "Laptop", 45000.00, 10};
    
    printf("Before update:\n");
    printf("ID: %d, Name: %s, Price: %.2f, Qty: %d\n", 
           prod.id, prod.name, prod.price, prod.quantity);
    
    // Direct update using dot operator
    prod.price = 42500.00;
    strcpy(prod.name, "Gaming Laptop");
    
    // Update using functions (pass by pointer)
    updatePrice(&prod, 41000.00);
    updateQuantity(&prod, 8);
    
    printf("\nAfter update:\n");
    printf("ID: %d, Name: %s, Price: %.2f, Qty: %d\n", 
           prod.id, prod.name, prod.price, prod.quantity);
    
    return 0;
}

View the complete Structures programs page.

Program Console Update structure values Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.