6

I wonder where strings are stored in Solidity?

Especially, where are string literals, function arguments, and variables stored?

I recall, I've read that strings cannot be saved to memory, but is that right?

eth
  • 85,679
  • 53
  • 285
  • 406
Shuzheng
  • 1,855
  • 3
  • 19
  • 31

1 Answers1

4

Strings can be stored in both Storage and Memory - it depends on the type of variable / usage - here's an example:


pragma solidity ^0.4.17;

contract StorageTest {

    string string1; // string1 is storage

    function func1(string param1) public pure { // param1 is memory
        string memory string2 = "foo";  // string2 is memory in this instance
    }
}

There's a great section in the Solidity documentation

And also a great answer from @eth about memory in Ethereum

SteveJaxon
  • 2,528
  • 1
  • 10
  • 21