1. Storage:
- A persistent data that is stored in the blockchain, mainly a global state variable of a contract is a storage.
- Once the state is declare in contract it is stored in contract permanently, and can be changed through the function call of the contract
- Writing to storage is costly (require more gas) because it require to change the state variable across the blockchain(i.e. every miner need to change the state after the update of that state), which involve consensus and storage allocation on the blockchain.
- e.g , here the userAddress is a storage data.
contract Storage{
address userAddress;
}
2. Memory:
- A temporary data storage, where the data is store until the function execution and discarded/remove from memory.
- As it is stored in memory, it is not persistent data in the blockchain and cannot access the data outside the function.
- It is cheaper (require less gas) to store the data in memory, cause it it removed after the need of the data i.e after the function execution.
- In function arguments and local variable, while passing the large structure like array, string into the function via function arguments it is stored in memory to reduce the gas cost.

3. Stack:
- A temporary data structure, where the small, temporary data is stored.
- It is same as the memory storage but data is stored in a special data structure, i.e stack
- It is similar to call stack in other programing language paradigm.