pragma solidity 0.8.0;
contract MemoryTest{
uint public num1 = 48;
uin[] arr;//在区块链上定义的uint[]
function add(uint num) public view returns(uint){
num = num +1;
return num;
}
function test1() public view returns(uint,uint){
uint i = 2;//i没有发生改变
uint j = add(i);
return(i,j);
}
function ChangeIt()public{
//num1 = 999;
add(num1);//然而num1并没有变化;changit函数只是将num1的值复制出来,再在函数add里面进行操作,因此并没有起到对合约里面的num1进行操作
}
//值传递时、会每个值开辟一个存储空间、互不影响;例子如下,j的改变不会影响i的值、i的改变不会影响j的值
function test2()public view returns(uint){
uint i = num1;
uint j = i;
j++;
return i;
}
function test3()public view returns(uint){
uint i = num1;
uint j = i;
i++;
return j;
}
function test4(uint[] array) returns(uint){
}
}
39.Solidity-Memory1
于 2022-11-20 20:16:23 首次发布