solidity, contract-development, storage, string, memory – Where Strings Are Stored in Solidity

contract-developmentmemorysoliditystoragestring

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?

Best Answer

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

Related Topic