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?
✗ Incorrect
Option A declares a dynamic array of addresses correctly using
address[].What happens if you try to add an element beyond the fixed size of a fixed array?
✗ Incorrect
Fixed-size arrays cannot change size, so adding beyond their size causes a compile-time error.
Which method is used to remove the last element from a dynamic array in Solidity?
✗ Incorrect
The
pop() method removes the last element from a dynamic array.Why might you choose a fixed-size array over a dynamic array in a smart contract?
✗ Incorrect
Fixed-size arrays use less gas and are more efficient when the size is known and constant.
How do you access the third element in a Solidity array named
myArray?✗ Incorrect
Array indexing starts at 0, so the third element is at index 2.
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.