Solidity - Arithmetic Operators



Addition operator (+) works for Numeric as well as Strings. e.g. "a" + 10 will give "a10".

Example

The following code shows how to use arithmetic operators in 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; 
   }
}

Run the above program using steps provided in Solidity First Application chapter.

Output

0: uint256: 3
solidity_operators.htm
Advertisements