Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c11bb24

Browse files
committed
Add example about array literals.
1 parent dfe07c0 commit c11bb24

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/types/reference-types.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,23 @@ memory arrays, i.e. the following is not possible:
237237
It is planned to remove this restriction in the future, but it creates some
238238
complications because of how arrays are passed in the ABI.
239239

240+
If you want to initialize dynamically-sized arrays, you have to assign the
241+
individual elements:
242+
243+
::
244+
245+
// SPDX-License-Identifier: GPL-3.0
246+
pragma solidity >=0.4.0 <0.7.0;
247+
248+
contract C {
249+
function f() public pure {
250+
uint[] memory x = new uint[](3);
251+
x[0] = 1;
252+
x[1] = 3;
253+
x[2] = 4;
254+
}
255+
}
256+
240257
.. index:: ! array;length, length, push, pop, !array;push, !array;pop
241258

242259
.. _array-members:

0 commit comments

Comments
 (0)