Solidity - 算術運算子



加法運算子 (+) 可用於數字和字串。例如,"a" + 10 將得到 "a10"。

示例

以下程式碼展示瞭如何在 Solidity 中使用算術運算子。

pragma solidity ^0.5.0;

contract SolidityTest {
   constructor() public{
   }
   function getResult() public view returns(uint){
      uint a = 1; 
      uint b = 2;
      uint result = a + b; //arithmetic operation
      return result; 
   }
}

使用 Solidity 第一個應用 章節中提供的步驟執行以上程式。

輸出

0: uint256: 3
solidity_operators.htm
廣告

© . All rights reserved.