基于以太坊的智能合约开发教程 Solidity 变量的生命周期与值传递
pragma solidity ^0.4.0;
contract valuecopy{
uint public a = 200;
// a = 100; 定义完之后不能给全局变量重新赋值,会报错
function test()public view returns(uint){
// 函数体内可对局部变量进行重新赋值
uint a =400;
a = 700;
return a;
}
function test1(uint a)public view returns(uint){
a = 700;
return a;
}
function test2(){
a = 8888;
}
uint public b = 300;
function test3()public view returns(uint,uint){
// 值传递,并不会改变变量原有的值,这里b1的值不会改变
uint a1 = 10;
uint b1 = a1;
a1 =19;
return (a1,b1);
}
function test4(uint mm) view returns(uint){
mm++;
return mm;
}
function test5() view returns(uint){
// 调用test4中的函数使得b进行自增,test5函数返回的结果会是b++;但是全局变量b的值并不会改变
return test4(b);
}
}