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,040 points
28 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,620 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
262 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
• 16,450 points
19 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
• 16,450 points
24 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
77 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.