codedamn

Strings

Created by Kshitij about a year ago

0

No description provided

7 Comments

    0

    // SPDX-License-Identifier: MIT pragma solidity >=0.5.0 <0.9.0;

    contract String { string public str = "Yes solidity is fun";

    function returnStateVariable() public view returns(string memory){
        return str;
    }
    
    function returnLocalVariable() public pure returns(string memory){
        string memory st = "Yes solidity is exciting";
        return st;
    }
    

    }

    why do I have to write memory keyword in returns even though i am returning a state variable (look at returnStateVariable function), i tried without memory keyword every time it was crashing.

    @sk9873422561

    Sandeep

    @sk9873422561

    0

    So at what stage can, we store a local variable for a contract at a storage level, since strings store at the memory level when the function is printing the objects

    @malima

    Samaila Anthony Malima

    @malima

    0

    In the program on string exercise, why do we need to pass (string memory) to print the state variable? In the Video you have explained we need memory keyword only to print local variable.

    @nehaapte0791

    Neha Apte

    @nehaapte0791

    0

    why the uint is getting printed as pure and not string?? can we use memory keyword with uint??

    @sumeettheracer

    Sumeet Biswas

    @sumeettheracer

    0

    What is the difference between memory and storage. When you are referring to memory and storage area, what exactly are you referring to? Pls elaborate on that

    @priyanshrai

    Priyansh Rai

    @priyanshrai

    0

    //SPDX-License-Identifier: UNLICENSED pragma solidity >= 0.5.0 < 0.9.0; contract strings{

    string public str="hi ashish don't lose hope";//state variable
    
    //functions in string
    function printInt() public pure returns(uint){
        uint age=34;
        return age;
    }
    //no string was used in the function thats why don't need to use the memory keyword
    
    
    function print() public pure returns(string memory){
        string memory str1= "hello ashish bhai";//str1 is a local variable
        return str1;
    

    //string used inside a function thats why we MUST use the keyword "memory" after the string //memory is nothing but a keyword that ensures that the data in the string is going to be stored on a memory level not on a storage level //the string at the top is storing the data on storage level;

    }
    

    }

    @ashish62da5810

    Ashish Prakash

    @ashish62da5810

    0

    In the editor if we have to return a state var which is string then we have to mention returns(string memory) instead of returns(string) why is that the case for state var though they are getting stored in the storage.

    @guily

    Mehul Ratra

    @guily

Your comment