LEARN SOLIDITY LESSON 3: Function Declarations. Private / Public Functions. Return Values of Functions.
LEARN SOLIDITY LESSON
Function Declarations. Private / Public Functions. Return Values of Functions.
Function Declarations
A function declaration in solidity looks like the following:
function eatHamburgers(string memory _name, uint _amount) public { }
//CALL
eatHamburgers("vitalik", 100);
Private and Public Functions
In Solidity, functions are public by default. Need practice to mark your functions as private by default, and then only make public the functions you want to expose to the world.
uint[] numbers;
//private
function _addToArray(uint _number) private {
}
//public
function addToArray(uint _number) public {
}
Return Values of Functions
function declaration contains the type of the return value. To return a value from a function, the declaration looks like this:
Summary for English Visiter
string strHello = "learn-solidity.blogspot.com"; function sayHello() public view returns (string memory) {
return strHello; }
function _multiply(uint a, uint b) private pure returns (uint) { return a * b; }
Comments