Recall & Review
beginner
What is a mapping in blockchain smart contracts?
A mapping is like a digital dictionary that links one value (a key) to another value. It helps store and find data quickly in smart contracts.
Click to reveal answer
beginner
How do you declare a mapping in Solidity?
You write:
mapping(KeyType => ValueType) public name; where KeyType is the type of the key and ValueType is the type of the value stored.Click to reveal answer
intermediate
Can you iterate over all keys in a mapping directly?
No, mappings do not store keys or allow iteration. You must keep a separate list of keys if you want to loop through them.
Click to reveal answer
beginner
What happens if you access a mapping with a key that does not exist?
You get the default value for the value type (like 0 for numbers or false for booleans), because mappings always return a value even if the key was never set.
Click to reveal answer
beginner
Why are mappings useful in blockchain smart contracts?
They let you store and quickly find data linked by keys, like user balances or permissions, without using lots of storage or complex searching.Click to reveal answer
How do you declare a mapping from addresses to unsigned integers in Solidity?
✗ Incorrect
The correct syntax uses '=>' to link key type to value type: mapping(address => uint).
What value do you get when accessing a mapping with a key that was never set?
✗ Incorrect
Mappings return the default value for the value type if the key does not exist.
Can you loop through all keys in a mapping directly?
✗ Incorrect
Mappings do not keep track of keys, so you cannot loop through them directly.
What is a common use of mappings in smart contracts?
✗ Incorrect
Mappings are often used to store balances or permissions linked to user addresses.
Which of these is NOT a valid key type for a mapping in Solidity?
✗ Incorrect
Mappings cannot have another mapping as a key type.
Explain what a mapping is and how it works in blockchain smart contracts.
Think of it like a digital dictionary that stores data linked by keys.
You got /4 concepts.
Describe how you would store and retrieve user balances using a mapping in Solidity.
Focus on how keys and values relate and how to get a balance.
You got /5 concepts.