Uninitialized storage pointer in solidity
Working with storage and memory variables can be a bit confusing in solidity. Using a storage variable inside a function can lead to unexpected behaviors.
In this recipe, you will learn to understand the importance of initializing a storage variable while declaring it.
Getting ready
It's expected that you have a basic understanding of the Ethereum blockchain and solidity before stepping through this recipe.
The Remix IDE (https://remix.ethereum.org) can help you quickly test and deploy the contract. Also, you can use any Ethereum client (geth
, parity
, and so on) and the solc
compiler to run this contract.
How to do it...
- Solidity allows you to choose the type of storage with the help of storageandmemory keywords. A storage variable stores values permanently, whereas memory variables are persisted during the lifetime of a transaction.
- Local variables of
struct
,array
, or mapping type reference storage by default if no explicit specification is given inside...