// 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: