pragma solidity ^0.8.9;
contract MemoryToMemoryReferenceTypeAssignment {
// Function 'getUInt' returns an unsigned integer
function getUInt() public returns (uint)
{
// Declare a new dynamic array 'someVar' in memory with 1 element
uint[] memory someVar = new uint[](1);
// Set the first element of 'someVar' to 23
someVar[0] = 23;
// Declare another memory array 'otherVar' and initialize it with 'someVar'
// This creates a reference to the same memory location as 'someVar'
uint[] memory otherVar = someVar;
// Modify the first element of 'someVar' to 45
// Since 'otherVar' references the same memory location, it is also updated
someVar[0] = 45;
// Return the first element of 'otherVar'
// It returns 45, demonstrating that both arrays reference the same memory
return (otherVar[0]);
}
}
//Dploy screenshoot show: