This content originally appeared on DEV Community and was authored by Loading Blocks
Preface
In Solidity, there are two kinds of arrays:
Fixed-size array:
You must specify array length at declaration time.
Example:uint[5] numbers;
Once created, the length is not possible to change.Dynamic-size array:
No need to specify length at declaration.
Example:uint[] numbers;
The length can be changed at runtime (grow or shrink).
Most common syntax
uint[5] numbers; // fixed size array
uint[] numbers; // dynamic array
numbers[i]; // access by index
uint[] storage refToNumbers = numbers; // storage reference
function f(uint[] memory a) external { ... } // pass memory array
numbers.push(x); // append to end
numbers.pop(); // remove the last element
uint n = numbers.length; // get length
delete numbers[i]; // reset value to default
for (uint i = 0; i < numbers.length; i++) { ... } // loop
Memory Arrays
When declaring an array inside a function, you must use the memory keyword.
A memory array always have fixed size, so you cannot call push or pop.
You can use the new
keyword to create a memory array based on a variable size.
Example:
function createMemoryArray(uint size) public pure returns (uint[] memory) {
uint[] memory newArr = new uint[](size);
return newArr;
}
This content originally appeared on DEV Community and was authored by Loading Blocks

Loading Blocks | Sciencx (2025-08-21T13:17:16+00:00) Solidity Arrays. Retrieved from https://www.scien.cx/2025/08/21/solidity-arrays/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.