Merge pull request #9457 from ethereum/docArrayLit

Add example about array literals.
This commit is contained in:
chriseth 2020-07-21 13:21:01 +02:00 committed by GitHub
commit eab999f753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -237,6 +237,23 @@ memory arrays, i.e. the following is not possible:
It is planned to remove this restriction in the future, but it creates some It is planned to remove this restriction in the future, but it creates some
complications because of how arrays are passed in the ABI. complications because of how arrays are passed in the ABI.
If you want to initialize dynamically-sized arrays, you have to assign the
individual elements:
::
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.0 <0.7.0;
contract C {
function f() public pure {
uint[] memory x = new uint[](3);
x[0] = 1;
x[1] = 3;
x[2] = 4;
}
}
.. index:: ! array;length, length, push, pop, !array;push, !array;pop .. index:: ! array;length, length, push, pop, !array;push, !array;pop
.. _array-members: .. _array-members: