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,350 points
1,402 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
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
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,400 points
4,768 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 21, 2018 in Blockchain by Perry
• 17,100 points
556 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,100 points
419 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
1,663 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,215 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP