// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract StorageToStorageReferenceTypeAssignment {
? ? // Define two state arrays, stateArray1 and stateArray2, both containing two uint elements.
? ? // stateArray1 initially contains [1, 2], and stateArray2 contains [3, 4].
? ? uint[2] stateArray1 = [uint(1), 2];
? ? uint[2] stateArray2 = [uint(3), 4];
? ? // In the following function:
? ? // - stateArray1 is assigned to be a reference to stateArray2.
? ? // - stateArray2's second element is updated to 5.
? ? // Therefore, stateArray1 now references the same storage location as stateArray2,
? ? // and the value of stateArray1[1] is 5.
? ? function getUInt() public returns (uint) {
? ? ? ? stateArray1 = stateArray2;
? ? ? ? stateArray2[1] = 5;
? ? ? ?
? ? ? ? // Returns the value of stateArray1's second element, which is 5 after the assignment.
? ? ? ? return stateArray1[1]; // returns 5
? ? }
}
//Deploy screenshoot: