Solidity – Why Was Memory Keyword Used in This Example

solidity

I am doing the cryptozombies.io course on Solidity.

In Chapter 7 of Making the Zombie Factory, it introduces function declarations. The instructions on this chapter are:

Create a public function named createZombie. It should take two parameters: _name (a string), and _dna (a uint). Don't forget to pass the first argument by value by using the memory keyword

My question is why is the _name parameter required to be declared with keyword memory (and similarly, why is the _dna parameter NOT required to be declared with keyword memory)?

In general, when does one declare a parameter using keyword memory and without it? I did Google about the memory keyword but I did not understand when it should be used and when it shouldn't.

Best Answer

Unsigned Integer or integers do not require memory specification when declared as arguments. Strings, arrays and structs require memory specification.

Related Topic