Simple Assignment Operator

The simple assignment operator(=) assigns the value of the right-hand operand to the left-hand operand.

Example:

uint a;

a = 10; // Assigns the value 10 to the variable a.

Below is the Solidity program to implement a simple assignment operator.

Solidity




// Solidity program to implement 
// simple assignment operator
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
  
contract AssignmentOperators {
    
  function basicAssignment() public pure returns (uint) 
  {
    uint a;
    a = 10;
      
    // a is now equal to 10
    return a;
  }
}


Output:

 

Solidity – Assignment Operators

Solidity is a high-level, statically-typed programming language for Ethereum smart contracts. Python, JavaScript, and C++ impact it. Solidity has several variable and value assignment operators. Solidity supports the following types of operators:

  1. Simple Assignment Operator.
  2. Arithmetic Assignment Operator.
  3. Bitwise Assignment Operator.

Similar Reads

Simple Assignment Operator

The simple assignment operator(=) assigns the value of the right-hand operand to the left-hand operand....

Arithmetic Assignment Operators

...

Bitwise Assignment Operators

These operators perform arithmetic operations and then assign the result to the left-hand operand. Solidity supports the following arithmetic assignment operators:...

Contact Us