Perform operations and return updated structure Dry Run in C

Perform operations and return updated structure 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.

Perform operations and return updated structure Program Code

#include <stdio.h>

struct BankAccount {
    int accNo;
    char holder[50];
    float balance;
};

struct BankAccount deposit(struct BankAccount acc, float amount) {
    acc.balance += amount;
    printf("Deposited: ₹%.2f\n", amount);
    return acc;
}

struct BankAccount withdraw(struct BankAccount acc, float amount) {
    if(amount <= acc.balance) {
        acc.balance -= amount;
        printf("Withdrawn: ₹%.2f\n", amount);
    } else {
        printf("Insufficient balance!\n");
    }
    return acc;
}

int main() {
    struct BankAccount account = {1001, "Sarah Johnson", 5000.00};
    
    printf("Initial Balance: ₹%.2f\n", account.balance);
    
    account = deposit(account, 2000);
    printf("After Deposit: ₹%.2f\n", account.balance);
    
    account = withdraw(account, 1500);
    printf("After Withdrawal: ₹%.2f\n", account.balance);
    
    account = withdraw(account, 6000);
    printf("Final Balance: ₹%.2f\n", account.balance);
    return 0;
}

View the complete Struct Functions Pointers programs page.

Program Console Perform operations and return updated structure Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.