Reference Types
arrays, structs, mappings.
What Are Reference Types?
Reference types describe data that is too large to fit in one slot, so variables refer to a location rather than holding the data directly.
The three reference types are arrays, structs, and mappings. When you use them you must think about their data location: storage, memory, or calldata.
Fixed-Size Arrays
A fixed-size array has a length set at compile time and cannot grow. The type uint[3] always holds exactly three values.
Use .length to read the size. Out-of-bounds access reverts.
<code>uint[3] public scores = [10, 20, 30];
function first() public view returns (uint) {
return scores[0];
}</code>All lessons in this course
- Value Types
- Reference Types
- Storage vs Memory
- Constants and Immutables