pragma solidity 0.7.5;
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;
// users[id].balance += balance;
}
function getBalance(uint id) view public returns (uint) {
return users[id].balance;
}
}
This is my solution, I noticed after reading other posts that the solution I got in the comment seems to be the most appropriate because we are talking about an update and not directly rewriting the balance value.
Even though the solution works just as well.