0
0
Blockchain / Solidityprogramming~5 mins

Arrays (fixed and dynamic) in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a fixed-size array in blockchain programming?
A fixed-size array is an array with a set number of elements that cannot change after declaration. Its size is known at compile time.
Click to reveal answer
beginner
How does a dynamic array differ from a fixed array?
A dynamic array can grow or shrink during runtime, allowing flexible storage of elements, unlike fixed arrays which have a constant size.
Click to reveal answer
beginner
In Solidity, how do you declare a fixed-size array of 5 unsigned integers?
You declare it like this: uint[5] fixedArray; This creates an array that holds exactly 5 unsigned integers.
Click to reveal answer
beginner
How do you add an element to a dynamic array in Solidity?
You use the push() method. For example: dynamicArray.push(10); adds the value 10 to the end of the array.
Click to reveal answer
intermediate
Why are fixed-size arrays more gas efficient than dynamic arrays in blockchain?
Fixed-size arrays have a known size at compile time, so they use less storage and gas. Dynamic arrays require extra gas to manage resizing and storage.
Click to reveal answer
Which of the following is a correct way to declare a dynamic array of addresses in Solidity?
Aaddress[] dynamicAddresses;
Baddress[5] dynamicAddresses;
Cdynamic address[];
Daddress dynamic[];
What happens if you try to add an element beyond the fixed size of a fixed array?
AThe element is added successfully.
BIt overwrites the last element.
CIt causes a compile-time error.
DIt automatically resizes the array.
Which method is used to remove the last element from a dynamic array in Solidity?
Adelete()
Bremove()
Cclear()
Dpop()
Why might you choose a fixed-size array over a dynamic array in a smart contract?
ATo allow flexible data storage.
BTo reduce gas costs and improve performance.
CBecause fixed arrays can grow automatically.
DBecause dynamic arrays are not supported.
How do you access the third element in a Solidity array named myArray?
AmyArray[2]
BmyArray[3]
CmyArray.get(3)
DmyArray.element(3)
Explain the difference between fixed-size and dynamic arrays in blockchain smart contracts.
Think about how the array size changes and gas costs.
You got /4 concepts.
    Describe how you would declare and use a dynamic array in Solidity.
    Focus on declaration, adding, removing, and accessing elements.
    You got /4 concepts.