Solidity-20 StorageToStorageValueTypeAssignment

发布时间:2024年01月21日

/// SPDX-License-Identifier: MIT

pragma solidity ^0.8.9;

contract StorageToStorageValueTypeAssignment {

? ? // Declare two state variables, stateVar1 and stateVar2, both of type uint.

? ? // Initialize stateVar1 with the value 20 and stateVar2 with the value 40.

? ? uint stateVar1 = 20;

? ? uint stateVar2 = 40;

? ? // In the following function:

? ? // - stateVar1 is assigned the value of stateVar2, which is 40.

? ? // - stateVar2 is updated to the value 50.

? ? // After these operations, stateVar1 holds the value 40, and stateVar2 holds the value 50.

? ? // The function returns the value of stateVar1, which is 40.

? ? function getUInt() public returns (uint) {

? ? ? ? stateVar1 = stateVar2;

? ? ? ? stateVar2 = 50;

? ? ? ? // Returns the value of stateVar1, which is 40 after the assignment.

? ? ? ? return stateVar1;

? ? }

}

// Deploy screenshoot:

文章来源:https://blog.csdn.net/m0_61408373/article/details/135734598
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。