This gist shows the difference between the usage of the keywords storage
and memory
in Solidity.
Note that by calling setValueMemory
then s
is not modified at all. So for example, if we initialize the contract, then s.value1
and s.value2
will be 0
. If we pass a 1
to this function and then we call the view getStruct
, it returns the old struct with the values 0
and 0
unchanged
By using storage
within the call to setValueStorage
we repeat the process above mentioned, but when we call the view getStruct
instead of getting 0
and 0
for the members of this struct, we get 1
for value1
. So it's modified.
You can see that the keyword storage
works like a pointer to s
here