Rule 3

Variables declared within functions, by default, are stored in memory data location. However, there are following few caveats:

  • The location for value type variables is memory within a function while the default for a reference type variable is storage.
Please note that storage is the default for reference type variable declared within a function. However, it can be overridden.
  • By overriding the default location, reference types variables can be located at the memory data location. The reference types referred are arrays, structs, and strings.
  • Reference types declared within a function without being overridden should always point to a state variable.
  • Value type variables declared in a function cannot be overridden and cannot be stored ...

Get Solidity Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.