Array
- Arrays are data structures that store the fixed collection of elements of the same data types in which each and every element has a specific location called index.
- Instead of creating numerous individual variables of the same type, we just declare one array of the required size and store the elements in the array and can be accessed using the index.
- In Solidity, an array can be of fixed size or dynamic size.
- Arrays have a continuous memory location, where the lowest index corresponds to the first element while the highest represents the last.
Fixed-size Arrays
The size of the array should be predefined. The total number of elements should not exceed the size of the array<data type>[ ] <array name> = <initialization>
Dynamic Arrays
The size of the array is not predefined when it is declared. As the elements are added the size of array changes and at the runtime, the size of the array will be determined.<data type>[ ] <array name> = <initialization>[Value1,Value2,.....]
Array Operations
- Accessing Array Elements
- Length of Array
- Push
- Array slices
- Pop
Video : Solidity Array
Resource File
Question / Answer
Fixed-size Arrays
<data type>[size] <array name> = <initialization>
Dynamic Arrays
<data type>[size] <array name> = <initialization>[Value1,Value2,.....]