Last active
November 3, 2020 12:12
-
-
Save wissalHaji/55ab0c0e78bcfa8dbad4e6eafc4ff220 to your computer and use it in GitHub Desktop.
test for data location assignments
This file contains 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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.7.0; | |
contract DataLocationTest { | |
uint[] stateVar = [1,4,5]; | |
function foo() public{ | |
// case 1 : from storage to memory | |
uint[] memory y = stateVar; // copy the content of stateVar to y | |
// case 2 : from memory to storage | |
y[0] = 12; | |
y[1] = 20; | |
y[2] = 24; | |
stateVar = y; // copy the content of y to stateVar | |
// case 3 : from storage to storage | |
uint[] storage z = stateVar; // z is a pointer to stateVar | |
z[0] = 38; | |
z[1] = 89; | |
z[2] = 72; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment