Data locations in Solidity
Unlike other programming languages, Solidity's variables are stored in the memory and the database, depending on the context.
There is always a default location, but it can be overridden for complex types of data, such as strings, arrays, and structs, by appending storage or memory to the type. Memory is the default for function parameters (including return
parameters), and storage is for local and state variables (obviously).
Data locations are important because they change the behavior of assignments:
- An independent copy is always created for assignments between storage variables and memory variables. No copy is created, however, for assignments from one memory-stored complex type to another.
- An independent copy is always created for an assignment to a state variable (even from other state variables).
- Memory-stored complex types cannot be assigned to local storage variables.
- If state variables are assigned to local storage variables, the local storage variables point...