ethereum(以太坊)(四)--值传递与引用传递

pragma solidity ^0.4.0;

// priveta public internal

contract Test{
uint public _age;
function Test(uint age){ _age = age; } function f(){ modify(_age); } function modify(uint age){ age =100; } //function age() constant returns(uint){ // return _age; //} } contract Person{ string _name; function Person(string name){ _name = name; } function f(){ modify(_name); } function modify(string storage name) internal { //name = 'eilinge'; //memory:值传递__https://pan.baidu.com/s/1cPn4aoXKeYZzD2cG15s28A,storage+internal+bytes():
     //引用传递__https://pan.baidu.com/s/1TO-1iAutc317VWp5iTS11g
bytes(name)[0] = 'L'; } function name() constant returns(string){ return _name; } }
值类型(Value Type)
    布尔(bool)
    整型(integer)
    地址(address)
    定长字节数组(fixed byte arrays)
    有理数和整型(Rational and Integer,String literals)
    枚举类型(Enums)
    函数(Functions Types)

    值类型传递时,会临时拷贝一份内容出来,而不是拷贝指针,当你修改新的变量时,不会影响原来的变量的值 

引用类型(Reference Types)
    不定长字节数组(bytes)
    字符串(string)
    数组(Array)
    结构体(Struts)
    
    引用类型,赋值时,可以值传递,也可以引用(地址传递)
        值传递:      当你修改新的变量时,不会影响原来的变量的值 
        引用传递:    当你修改新变量时,原来变量的值会跟着变化,这是因为新/旧变量指向同一个地址的原因。

猜你喜欢

转载自www.cnblogs.com/eilinge/p/9952381.html
今日推荐