Created
October 18, 2021 04:24
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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