1

This post (When should I use calldata and when should I use memory?) explains the differences between calldata and memory. However where are function arguments or variables within functions stored if nothing is specified aka what is the default for each?

Examples:

function foo(string _exampleString) // where is the argument stored?

vs 

function foo(string memory _exampleString)

or

function foo(string _exampleString) public{
   uint256 memory bar = 1;
}

vs 

function foo(string _exampleString) public {
    uint256 bar = 1;   // where is the argument stored?
}

1 Answer 1

0

As you can read on this documentation function arguments are always in memory. So both options will store the value on memory.

1
  • that doesn't really answer my question. My question is why would you specify memory to a function argument if its the default place to be stored? why would you speciy calldata explicitly? Besides funciton arguments can also be stored in storage Nov 12, 2021 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.