Data Location Assignment Solution - Gaurav Sahoo

pragma solidity 0.8.4;
contract MemoryAndStorage {

mapping(uint => User) users;

struct User{
    uint id;
    uint balance;
}

function addUser(uint id, uint balance) public {
    users[id] = User(id, balance);
}

function updateBalance(uint id, uint _balance) public {
    
   users[id].balance += _balance;

}

function getBalance(uint id) view public returns (uint) {
    return users[id].balance;
}

}

1 Like