What are the two main categories of integer types in Rust?
Signed integers (can be positive or negative) and unsigned integers (only positive and zero).
Click to reveal answer
beginner
What does i32 mean in Rust?
i32 is a signed 32-bit integer type. It can store values from -2,147,483,648 to 2,147,483,647.
Click to reveal answer
beginner
What is the difference between u8 and i8 in Rust?
u8 is an unsigned 8-bit integer (0 to 255), while i8 is a signed 8-bit integer (-128 to 127).
Click to reveal answer
intermediate
Why would you choose an unsigned integer type in Rust?
Use unsigned integers when you know the value will never be negative, which allows storing a larger positive range.
Click to reveal answer
intermediate
What happens if you try to store a number outside the range of an integer type in Rust?
Rust will cause a compile-time error or panic in debug mode due to overflow or underflow, helping catch bugs early.
Click to reveal answer
Which Rust integer type can store the value -100?
Ai32
Bu32
Cu8
Dusize
✗ Incorrect
i32 is signed and can store negative numbers like -100. Unsigned types like u32 and u8 cannot.
What is the range of values for u16 in Rust?
A-128 to 127
B-32,768 to 32,767
C0 to 65,535
D0 to 255
✗ Incorrect
u16 is an unsigned 16-bit integer, so it stores values from 0 to 65,535.
Which integer type is best for counting items that can never be negative?
Ai64
Bu64
Ci8
Disize
✗ Incorrect
u64 is unsigned and can only hold zero or positive numbers, perfect for counting.
What does isize represent in Rust?
AA floating-point number
BAn unsigned 32-bit integer
CA fixed 64-bit unsigned integer
DA signed integer with size depending on the computer architecture
✗ Incorrect
isize is a signed integer whose size depends on the system (32-bit or 64-bit).
What will happen if you add 1 to the maximum value of u8 in debug mode?
AIt causes a panic (runtime error)
BIt becomes a negative number
CIt wraps around to 0 without error
DIt converts to a larger integer type automatically
✗ Incorrect
In debug mode, Rust checks for overflow and will panic if it happens, helping catch bugs.
Explain the difference between signed and unsigned integer types in Rust.
Think about whether the number can be negative or not.
You got /3 concepts.
Describe what happens when integer overflow occurs in Rust during debug mode.
Consider how Rust protects you from mistakes with numbers.
You got /3 concepts.
Practice
(1/5)
1. Which Rust integer type can store only positive whole numbers including zero?
easy
A. u32
B. i32
C. f32
D. bool
Solution
Step 1: Understand signed vs unsigned integers
Signed integers (i32) store negative and positive numbers, unsigned (u32) store only zero and positive numbers.
Step 2: Identify the type that stores only positive whole numbers
u32 is unsigned 32-bit integer, so it stores only positive whole numbers including zero.
Final Answer:
u32 -> Option A
Quick Check:
Unsigned integer = u32 [OK]
Hint: Unsigned integers start with 'u' and hold only positive numbers [OK]
Common Mistakes:
Confusing signed and unsigned types
Choosing floating-point types for whole numbers
Thinking bool is an integer type
2. Which of the following is the correct way to declare a 16-bit signed integer variable named x with value 100 in Rust?
easy
A. let x: u16 = 100;
B. let x: i16 = 100;
C. let x i16 = 100;
D. let x: int16 = 100;
Solution
Step 1: Check Rust syntax for typed variable declaration
Rust uses let variable_name: type = value; syntax.
Step 2: Identify the correct 16-bit signed integer type
i16 is the 16-bit signed integer type in Rust.
Final Answer:
let x: i16 = 100; -> Option B
Quick Check:
Typed variable declaration with i16 = let x: i16 = 100; [OK]
Hint: Use 'let var: i16 = value;' for 16-bit signed integers [OK]
Common Mistakes:
Using unsigned type u16 instead of signed
Using invalid type name int16
Incorrect syntax like missing colon
3. What will be the output of this Rust code?
let a: i8 = 127;
let b: i8 = 1;
let c = a.wrapping_add(b);
println!("{}", c);
medium
A. 128
B. 0
C. -128
D. Overflow error
Solution
Step 1: Understand i8 max value and wrapping_add behavior
The max value for i8 is 127. Adding 1 causes overflow. wrapping_add wraps around instead of panicking.
Step 2: Calculate the wrapped result
127 + 1 wraps to -128 in i8 range.
Final Answer:
-128 -> Option C
Quick Check:
Wrapping addition overflow wraps to -128 [OK]
Hint: wrapping_add wraps on overflow, not error [OK]
Common Mistakes:
Expecting 128 which is out of i8 range
Thinking it causes runtime panic
Confusing wrapping_add with normal addition
4. Identify the error in this Rust code snippet:
let x: u8 = -5;
medium
A. Missing semicolon
B. Type u8 does not exist
C. Variable name invalid
D. Negative value assigned to unsigned integer
Solution
Step 1: Check the type and value compatibility
u8 is unsigned 8-bit integer and cannot hold negative values.
Step 2: Identify the error cause
Assigning -5 to u8 causes a type mismatch error.
Final Answer:
Negative value assigned to unsigned integer -> Option D
Quick Check:
Unsigned integer cannot hold negative values [OK]
Hint: Unsigned types cannot hold negative numbers [OK]
Common Mistakes:
Ignoring negative sign allowed in unsigned types
Thinking semicolon is missing
Assuming variable name is invalid
5. You need to store the number of stars in the Milky Way galaxy, approximately 20,000,000,000,000,000,000 (20 quintillion). Which Rust integer type should you choose to store this number safely?
hard
A. u128
B. i64
C. u64
D. i32
Solution
Step 1: Understand the size limits of integer types
u64 max is about 18 quintillion, which cannot hold 20 quintillion. i64 max is about 9 quintillion. u128 is necessary.
Step 2: Choose the type that safely stores 20 quintillion
u128 can store very large positive integers up to 3.4e38, safely holding 20 quintillion.
Final Answer:
u128 -> Option A
Quick Check:
Use u128 for very large positive integers [OK]
Hint: Use u128 for very large positive integers beyond u64 [OK]
Common Mistakes:
Choosing signed types unnecessarily
Using i32 which is too small
Assuming u64 is always enough without checking limits
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.