0
0
Blockchain / Solidityprogramming~5 mins

State variables in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a state variable in blockchain smart contracts?
A state variable is a variable whose value is permanently stored on the blockchain. It keeps data between function calls and transactions.
Click to reveal answer
beginner
Where are state variables stored in a blockchain smart contract?
State variables are stored in the contract's storage on the blockchain, making their values persistent and shared across all users.
Click to reveal answer
beginner
How do state variables differ from local variables in smart contracts?
State variables are stored permanently on the blockchain, while local variables exist only temporarily during function execution and are not saved.
Click to reveal answer
intermediate
Why should you be careful when updating state variables in smart contracts?
Updating state variables costs gas (transaction fees) because it changes blockchain storage. Minimizing updates saves cost and improves efficiency.
Click to reveal answer
beginner
Give an example of declaring a state variable in Solidity.
Example:
uint public count;
This declares a state variable named count of type unsigned integer, stored on the blockchain.
Click to reveal answer
What happens to a state variable's value after a smart contract function finishes execution?
AIt is saved permanently on the blockchain.
BIt is deleted immediately.
CIt resets to zero.
DIt becomes a local variable.
Which of these variables is stored temporarily during function execution?
AState variable
BLocal variable
CGlobal variable
DConstant variable
Why does updating a state variable cost gas in Ethereum?
ABecause it changes the blockchain storage.
BBecause it sends tokens.
CBecause it calls another contract.
DBecause it reads data.
Which keyword is used to declare a state variable in Solidity?
Auint
Bstorage
Cmemory
Dpublic
Where are state variables stored?
AIn temporary memory during execution
BIn the user's local machine
CIn the contract's storage on the blockchain
DIn the transaction logs only
Explain what state variables are and why they are important in blockchain smart contracts.
Think about how data stays saved between transactions.
You got /3 concepts.
    Describe the difference between state variables and local variables in smart contracts.
    Consider where each variable lives and how long it lasts.
    You got /3 concepts.