Rust Data Types Quiz
45 comprehensive questions on Rust's type system, covering scalar types, compound types, type conversions, numeric operations, and string types — with 15 code examples demonstrating practical type usage patterns.
Question 1
What are the four primary scalar types in Rust?
Question 2
How many bits does an i32 integer type represent?
Question 3
What is the default integer type in Rust when you don't specify one?
Question 4
What happens when you try to add two different integer types without explicit conversion?
Question 5
Which of these is a valid floating-point literal in Rust?
Question 6
What is the difference between f32 and f64 floating-point types?
Question 7
How do you represent a single character in Rust?
Question 8
What will this code output?
fn main() {
let c = 'z';
let z = 'ℤ';
let heart_eyed_cat = '😻';
println!("Characters: {}, {}, {}", c, z, heart_eyed_cat);
}Question 9
What are compound types in Rust?
Question 10
How do you declare a tuple in Rust?
Question 11
How do you access elements of a tuple?
Question 12
What is destructuring in the context of tuples?
Question 13
How do you declare an array in Rust?
Question 14
What happens if you try to access an array element beyond its bounds?
Question 15
How do you create an array with the same value repeated?
Question 16
What is the key difference between arrays and vectors in Rust?
Question 17
How do you perform explicit type conversion (casting) in Rust?
Question 18
When building a graphics application that needs to convert floating-point colors to integer pixel values, how should you handle the conversion?
Question 19
What happens when you cast a large integer to a smaller type?
Question 20
What will this code output?
fn main() {
let decimal = 65.4321_f32;
let integer = decimal as u8;
let character = integer as char;
println!("{} -> {} -> {}", decimal, integer, character);
}Question 21
What are the two main string types in Rust?
Question 22
What is the difference between String and &str?
Question 23
How do you create a new String?
Question 24
What happens when you try to modify a string literal?
Question 25
How do you convert a String to a &str?
Question 26
What will this code output?
fn main() {
let mut s = String::from("Hello");
s.push_str(", world!");
println!("{}", s);
}Question 27
How do you concatenate strings in Rust?
Question 28
What is UTF-8 encoding in the context of Rust strings?
Question 29
When processing user input that contains international characters, what should you be aware of?
Question 30
What are the basic arithmetic operations available for numeric types?
Question 31
What happens when integer arithmetic overflows in debug mode?
Question 32
How can you explicitly handle integer overflow?
Question 33
In a financial application where you need to prevent monetary value overflow, which overflow handling method should you use?
Question 34
What is the difference between f32 and f64 division results?
Question 35
How do you access individual bytes of a string?
Question 36
What will this code output?
fn main() {
let s = "Hello, 世界!";
println!("Bytes: {:?}", s.as_bytes());
println!("Length: {}", s.len());
}Question 37
Why is string indexing by integer potentially dangerous in Rust?
Question 38
How do you iterate over characters in a string properly?
Question 39
When implementing a text processing function that needs to handle international text correctly, what approach should you use?
Question 40
What is the result of this arithmetic expression?
fn main() {
let result = 10u32.saturating_add(20u32);
println!("Result: {}", result);
}Question 41
How do you create a tuple with mixed types?
Question 42
What happens when you try to access a tuple element that doesn't exist?
Question 43
In a graphics application where you need to represent RGBA color values, which type would be most appropriate?
Question 44
How do you convert between numeric types safely?
Question 45
When processing a large dataset where you need to ensure no data loss during type conversions, what approach should you use?
