Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Day 7 - Functions
Vedant Chainani
Vedant Chainani

Posted on • Edited on

     

Day 7 - Functions

GitHub logo 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}
Enter fullscreen modeExit fullscreen mode

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;}}
Enter fullscreen modeExit fullscreen mode

view in a function ensures that they will not modify the state of the function.


Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Web3 Technical Writer ✍️ | ⛓️ Blockchain Enthusiast
  • Location
    India
  • Joined

More fromVedant Chainani

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp