0
0
Blockchain / Solidityprogramming~5 mins

Constants and immutables in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a constant in blockchain programming?
A constant is a value that is set once and cannot be changed during the execution of a smart contract. It helps keep data safe and predictable.
Click to reveal answer
beginner
What does 'immutable' mean in the context of blockchain variables?
Immutable means the variable can be assigned only once during contract creation and cannot be changed afterward, ensuring fixed data after deployment.
Click to reveal answer
intermediate
Why use constants and immutables in smart contracts?
They save gas (transaction cost) and increase security by preventing accidental or malicious changes to important values.
Click to reveal answer
intermediate
How do constants differ from immutables in blockchain code?
Constants are fixed at compile time and cannot be changed ever. Immutables are set once during contract deployment and then stay fixed.
Click to reveal answer
beginner
Example: What happens if you try to change a constant value in a smart contract?
The code will not compile or will throw an error because constants cannot be modified after they are set.
Click to reveal answer
Which of the following is true about constants in blockchain smart contracts?
AThey are only used for temporary values.
BThey can be changed anytime during contract execution.
CThey are set during contract deployment and can be changed later.
DThey are set once and cannot be changed ever.
What is the main difference between constants and immutables?
AImmutables can be changed anytime; constants cannot.
BConstants are cheaper to use than immutables.
CConstants are set at compile time; immutables are set once during deployment.
DThere is no difference.
Why do constants and immutables save gas in smart contracts?
ABecause their values are stored in cheaper ways and not changed.
BBecause they allow unlimited changes.
CBecause they increase contract size.
DBecause they require more computation.
When can an immutable variable be assigned a value?
AOnly once during contract deployment.
BMultiple times during contract execution.
COnly after contract deployment.
DNever assigned a value.
What happens if you try to modify a constant after deployment?
AThe contract crashes at runtime.
BThe contract will not compile or will throw an error.
CThe contract ignores the change silently.
DThe constant value changes successfully.
Explain the difference between constants and immutables in blockchain smart contracts.
Think about when each value is assigned and if it can change later.
You got /4 concepts.
    Why is it important to use constants and immutables in smart contract development?
    Consider how fixed values help protect your contract and save costs.
    You got /4 concepts.