What is the difference between the below two array?
without new
keyword: bool[3] fixedArray;
with new
keyword: bool[] fixedArray2 = new bool[](3);
What is the difference between the below two array?
without new
keyword: bool[3] fixedArray;
with new
keyword: bool[] fixedArray2 = new bool[](3);
The new
keyword is used to initialise arrays in memory. From the docs:
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; } }