Solidity Programming Language – Fixed Sized Array
fixed-size arrays are arrays with a predefined and fixed number of elements. These arrays have a specific size that is determined at the time of declaration and cannot be changed during the execution of the contract. Fixed-size arrays are denoted by specifying the size in square brackets when declaring the array.
Fixed-size arrays are useful when you know the exact number of elements you need, and you want to enforce a specific size for the array. They are efficient in terms of gas costs because the size is known at compile time, and no dynamic resizing is required.
Keep in mind that using fixed-size arrays may not be suitable in situations where you need a dynamic size or if the size of the array depends on external factors. In such cases, you may want to consider using dynamic arrays (uint[]
) or other data structures based on your requirements.
Code:
If we type 5 in front of are no response we are getting as it’s out of bound. Even if we try -1 we are not getting any value in response.
Add below mention line in previous code: