Solidity 053Parameters

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.9;

// Contract named Parameters to demonstrate function parameters and return types

contract Parameters {

    // Function with a single incoming parameter. It returns the parameter value multiplied by 2.

    // @param _data The input integer to be doubled.

    // @return _output The doubled value of the input.

    function singleIncomingParameter(int _data) public pure returns (int _output) {

        return _data * 2;

    }

   

    // Function with multiple incoming parameters. It returns the product of the two parameters.

    // @param _data First input integer.

    // @param _data2 Second input integer.

    // @return _output The product of the two input integers.

    function multipleIncomingParameter(int _data, int _data2) public pure returns (int _output) {

        return _data * _data2;

    }

   

    // Function with a single incoming parameter and multiple outgoing parameters.

    // It calculates the square and half of the input parameter.

    // @param _data The input integer.

    // @return square The square of the input integer.

    // @return half The half of the input integer.

    function multipleOutgoingParameter(int _data) public pure returns (int square, int half) {

        square = _data * _data; // Calculate square of _data

        half = _data / 2; // Calculate half of _data

    }

   

    // Function with a single incoming parameter and multiple outgoing parameters using tuple for return.

    // It calculates and returns the square and half of the input parameter in a single line.

    // @param _data The input integer.

    // @return square The square of the input integer.

    // @return half The half of the input integer.

    function multipleOutgoingTuple(int _data) public pure returns (int square, int half) {

        (square, half) = (_data * _data, _data / 2); // Simultaneously calculate square and half of _data

    }

}

//Deploy:

  • 21
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值