pragma solidity ^0.4.0; contract modifierTest{ uint public v1; uint constant v2 =10; //uint constant v3; Uninitialized "constant" variable string public v4='test1'; string constant v5='test2'; //string constant v6;Uninitialized "constant" variable function f() public{ v1 = 10; //v2 = 20;Cannot assign to a constant variable v4 = 'vtesst'; //v5 = 'vtest2';Cannot assign to a constant variable } struct test{ string name; uint _sex; } //test constant test1; constant 仅可以修饰值类型,无法修饰引用类型(string除外) function set() constant public{ //被修饰的函数内,状态变量无法被改变 v1 =100; } //告诉编译器,函数不改变/不读取状态变量,这样函数执行就可以不消耗gas了,因为不需要矿工来验证 // 1.view 仅可以修饰函数 // 2.在该函数内,仅可以对storage类型的变量进行读取,无法修改 address owner; function setview(address add) view public { owner = add; } function getadd()returns(address){ return owner; } // 1.pure 仅可以修饰函数 // 2.在函数内,无法读写状态变量-- }