Skip to content

Instantly share code, notes, and snippets.

@Rhynorater
Created October 18, 2021 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rhynorater/053f4eecf32e1586880b3696b96fdebd to your computer and use it in GitHub Desktop.
Save Rhynorater/053f4eecf32e1586880b3696b96fdebd to your computer and use it in GitHub Desktop.
Example of Differences in Data Locations When Creating New Variables (Storage -> Storage vs Storage -> Memory)
pragma solidity ^0.8.0;
contract Demo{
event log(string data);
string public d= "This is a variable";
string public mv = "changed";
string public mv2 = "changed2";
constructor () {
string storage x = d;
string storage y = x; // Change this to: string memory y = x;
emit log(x);
emit log(y);
d = mv;
emit log(x);
emit log(y);
y = mv2;
emit log(x);
emit log(y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment