Recall & Review
beginner
What are compound data types in Rust?
Compound data types group multiple values into one type. In Rust, common compound types are tuples and arrays.
Click to reveal answer
beginner
How do you define a tuple in Rust?
A tuple is defined by listing values inside parentheses, separated by commas. Example: <code>let t = (10, 20, 30);</code>Click to reveal answer
beginner
How do you access elements in a tuple?
Use a dot and the index number starting at zero. Example: <code>let x = t.1;</code> gets the second element.Click to reveal answer
intermediate
What is the difference between arrays and tuples in Rust?
Arrays hold multiple values of the same type and have fixed length. Tuples can hold different types and also have fixed length.
Click to reveal answer
beginner
How do you declare an array of five integers in Rust?
Use square brackets with the type and length. Example: <code>let arr: [i32; 5] = [1, 2, 3, 4, 5];</code>Click to reveal answer
Which of these is a valid tuple in Rust?
✗ Incorrect
Tuples use parentheses and can hold different types, like (10, "hello", true).
How do you access the third element of a tuple named
t?✗ Incorrect
Tuple elements are accessed with dot and zero-based index, so t.2 is the third element.
What is true about Rust arrays?
✗ Incorrect
Rust arrays have fixed size and all elements must be the same type.
Which syntax correctly declares an array of 3 floats?
✗ Incorrect
Arrays use square brackets with type and length: [f32; 3].
What happens if you try to access an array element out of bounds in Rust?
✗ Incorrect
Rust checks array bounds at runtime and panics if out of bounds to prevent errors.
Explain what compound data types are in Rust and give examples.
Think about how multiple values are grouped in Rust.
You got /3 concepts.
Describe how to declare and access elements in a tuple and an array in Rust.
Remember tuples use parentheses and dot notation; arrays use square brackets.
You got /4 concepts.