
Envoy-VC / 30-Days-of-Solidity
30 Days of Solidity step-by-step guide to learn Smart Contract Development.
This is Day7
of30
in Solidity Series
Today I Learned About Functions in Solidity.
A function is basically a group of code that can be reused anywhere in the program, which generally saves the excessive use of memory and decreases the runtime of the program. Creating a function reduces the need of writing the same code over and over again.
Syntax -
functionfunction_name(parameter_list)scopereturns(return_type){// block of code}
eg-
// SPDX-License-Identifier: MITpragmasolidity^0.8.7;contractMyContract{functionadd()publicviewreturns(uint256){uint256num1=10;uint256num2=16;uint256sum=num1+num2;returnsum;}functionsqrt(uint256num)publicpurereturns(uint256){num=num**2;returnnum;}}
view
in a function ensures that they will not modify the state of the function.
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse