Solidity Solidity Data Types and Storage 1 — Questions and Answers
Question 1: Which of the following is a value type in Solidity?
- bytes (dynamic)
- string
- uint256 (Correct answer)
- mapping
Correct answer: uint256
uint256 is a value type stored directly on the stack, while bytes, string, and mapping are reference types.
Question 2: What is the default value of an uninitialized bool state variable in Solidity?
- null
- true
- false (Correct answer)
- undefined
Correct answer: false
In Solidity, all uninitialized state variables are set to their zero value; for bool that is false.
Question 3: What is the maximum value that can be stored in a uint8 in Solidity?
- 127
- 255 (Correct answer)
- 256
- 65535
Correct answer: 255
uint8 is an 8-bit unsigned integer, so its maximum value is 2^8 - 1 = 255.
Question 4: Which Solidity type correctly declares a fixed-size byte array of exactly 32 bytes?
- byte[32]
- bytes(32)
- bytes32 (Correct answer)
- fixed32
Correct answer: bytes32
bytes32 is Solidity's built-in fixed-size byte array type that holds exactly 32 bytes.
Question 5: What is the key difference between int256 and uint256 in Solidity?
- int256 uses less gas than uint256
- uint256 can only store even numbers
- int256 can store negative values while uint256 cannot (Correct answer)
- They are identical types with different names
Correct answer: int256 can store negative values while uint256 cannot
int256 is a signed integer that can hold both positive and negative values, while uint256 is unsigned and only holds non-negative values.
Question 6: What is the byte size of the address type in Solidity?
- 16 bytes
- 20 bytes (Correct answer)
- 32 bytes
- 64 bytes
Correct answer: 20 bytes
An Ethereum address is always 20 bytes (160 bits), so the address type in Solidity occupies 20 bytes of storage.
Question 7: Which Solidity integer type is recommended for most use cases to avoid implicit conversion issues?
- int8
- uint32
- uint256 (Correct answer)
- int128
Correct answer: uint256
uint256 is the default and most commonly used integer type in Solidity, matching the EVM's native 256-bit word size and minimizing implicit conversion overhead.
Which of the following is a value type in Solidity?