0
0
Blockchain / Solidityprogramming~20 mins

Data types (uint, int, bool, address, string) in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Blockchain Data Types
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Solidity code snippet?

Consider the following Solidity function that returns a boolean and an integer:

function test() public pure returns (bool, int) {
    int a = -10;
    bool b = a < 0;
    return (b, a * 2);
}

What will be the returned values?

Blockchain / Solidity
function test() public pure returns (bool, int) {
    int a = -10;
    bool b = a < 0;
    return (b, a * 2);
}
A(false, -20)
B(false, 20)
C(true, 20)
D(true, -20)
Attempts:
2 left
💡 Hint

Remember that int can hold negative values and the comparison a < 0 checks if a is negative.

Predict Output
intermediate
2:00remaining
What is the value of the address variable after assignment?

Given this Solidity code snippet:

address addr = 0x1234567890123456789012345678901234567890;
address zeroAddr = address(0);
bool isZero = (addr == zeroAddr);

What is the value of isZero?

Blockchain / Solidity
address addr = 0x1234567890123456789012345678901234567890;
address zeroAddr = address(0);
bool isZero = (addr == zeroAddr);
Atrue
BCompilation error
Cfalse
DRuntime error
Attempts:
2 left
💡 Hint

The zero address is a special address with all zeros. Check if addr matches it.

Predict Output
advanced
2:00remaining
What is the output of this Solidity string comparison?

Consider this Solidity function:

function compareStrings() public pure returns (bool) {
    string memory a = "hello";
    string memory b = "hello";
    return keccak256(bytes(a)) == keccak256(bytes(b));
}

What does this function return?

Blockchain / Solidity
function compareStrings() public pure returns (bool) {
    string memory a = "hello";
    string memory b = "hello";
    return keccak256(bytes(a)) == keccak256(bytes(b));
}
Afalse
Btrue
CCompilation error
DRuntime error
Attempts:
2 left
💡 Hint

Strings in Solidity cannot be compared directly. Instead, their hashes are compared.

Predict Output
advanced
2:00remaining
What error does this Solidity code raise?

Analyze this Solidity snippet:

uint8 x = 255;
x = x + 1;

What happens when this code runs?

Blockchain / Solidity
uint8 x = 255;
x = x + 1;
AOverflow error (runtime revert in Solidity 0.8+)
Bx becomes 0 without error
CCompilation error
Dx becomes 256
Attempts:
2 left
💡 Hint

Since Solidity 0.8, arithmetic overflow causes a runtime error.

🧠 Conceptual
expert
2:00remaining
Which data type is best suited for storing Ethereum wallet addresses?

In Solidity, which data type should you use to store Ethereum wallet addresses securely and efficiently?

Aaddress
Buint256
Cstring
Dbool
Attempts:
2 left
💡 Hint

Ethereum addresses have a special data type designed for them.