Solidity difference array with and without new keyword.

0 votes
I have seen two ways to create arrays.

without new keyword: bool[3] fixedArray;

with new keyword: bool[] fixedArray2 = new bool[](3);

Can someone explain the difference between these two types?
Aug 16, 2018 in Blockchain by slayer
• 29,050 points
37 views

1 answer to this question.

0 votes

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;

    }

}

Source: Solidity docs

answered Aug 16, 2018 by digger
• 27,630 points

Related Questions In Blockchain

0 votes
1 answer
+1 vote
1 answer

What is the difference between if() and require() statement in solidity??

If() and require() have separate functions and ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,330 points
342 views
0 votes
1 answer

Is it that new bitcoins gets created with the every block mined??

Bitcoin mining means validation of a block ...READ MORE

answered Apr 20, 2018 in Blockchain by Perry
• 17,010 points
29 views
0 votes
1 answer

Can we protect a Private Blockchain with a Public Blockchain and how?

I have recently reviewed Exonum framework (https://exonum.com/) ...READ MORE

answered Jun 19, 2018 in Blockchain by Perry
• 17,010 points
31 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
126 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer