Skip to main content
Fix title grammar
Link
Ismael
  • 30.3k
  • 23
  • 54
  • 97

i got Why did I get an error whileabout using memory keyewordkeyword in function getname() why?

// SPDX-License-Identifier: MIT pragma solidity ^0.7.0;

contract s12 { uint public age; string public name; bool rollno;

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

contract s12 {
    uint public age;
    string public name;
    bool rollno;
    
    constructor() public {
        rollno= false;
    } 

    function setname(string memory newName) public {
      name=newName;
    }

    function  getname() public view returns (string){
      return name;
    }

    function setAge(string  memory newAge) public {
      age=newAge;
    }

    function getAge() public view returns(uint){
      return age;
    }
 }

function setname(string memory newName) public { name=newName; } function getname() public view returns (string){ return name;

} function setAge(string memory newAge) public { age=newAge; } function getAge() public view returns(uint){ return age; } }

// SPDX-License-Identifier: MIT pragma solidity ^0.7.0;

contract s12 { uint public age; string public name; bool rollno;

constructor() public {
    rollno= false;
}

function setname(string memory newName) public { name=newName; } function getname() public view returns (string){ return name;

} function setAge(string memory newAge) public { age=newAge; } function getAge() public view returns(uint){ return age; } }

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

contract s12 {
    uint public age;
    string public name;
    bool rollno;
    
    constructor() public {
        rollno= false;
    } 

    function setname(string memory newName) public {
      name=newName;
    }

    function  getname() public view returns (string){
      return name;
    }

    function setAge(string  memory newAge) public {
      age=newAge;
    }

    function getAge() public view returns(uint){
      return age;
    }
 }
Source Link

i got an error while using memory keyeword in function getname() why?

// SPDX-License-Identifier: MIT pragma solidity ^0.7.0;

contract s12 { uint public age; string public name; bool rollno;

constructor() public {
    rollno= false;
}

function setname(string memory newName) public { name=newName; } function getname() public view returns (string){ return name;

} function setAge(string memory newAge) public { age=newAge; } function getAge() public view returns(uint){ return age; } }