Solidity has 3 difference memory storage: storage, memory and stack. After reading lots of articles online, I still can't understand the difference between memory and stack. My question would be:
Q1. What's the difference between memory and stack?
Q2. Suppose I have defined a local variable in function, how do I know that this variable is stored in memory or stack? (The variable is in memory only if the declaration of the variable goes with the "memory" keyword?)
Thanks, everyone.
Thanks for the reply from @Yilmaz . According to your answer, say we have a function written like this:
function test() public {
string memory str;
int i;
}
Are str
and i
both on "memory" and on "stack" simultaneously?
My third question is:
Q3. Why do only array, struct, and mapping types need to specify memory location?
Why Solidity doesn't allow me to write int memory i;
in above code?