在 solidity 中创建一个新的固定大小的数组

Create a new fixed size array in solidity

下面两个数组有什么区别?

没有 new 关键字:bool[3] fixedArray;

使用 new 关键字:bool[] fixedArray2 = new bool[](3);

new关键字用于初始化数组内存。来自文档:

Allocating Memory Arrays

Creating arrays with variable length in memory can be done using the new keyword. As opposed to storage arrays, it is not possible to resize memory arrays by assigning to the .length member.

pragma solidity ^0.4.16;

contract C {
    function f(uint len) public pure {
        uint[] memory a = new uint[](7);
        bytes memory b = new bytes(len);
        // Here we have a.length == 7 and b.length == len
        a[6] = 8;
    }
}