0
0
Rustprogramming~10 mins

Compound data types in Rust - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a tuple with an integer and a string.

Rust
let my_tuple = ([1], "hello");
Drag options to blanks, or click blank then click option'
A42
B3.14
Ctrue
D"world"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a string instead of an integer for the first element.
2fill in blank
medium

Complete the code to access the second element of the tuple.

Rust
let second = my_tuple.[1];
Drag options to blanks, or click blank then click option'
A2
B0
C1
D3
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using index 2 or higher which is out of range for a two-element tuple.
3fill in blank
hard

Fix the error in the code to create an array of integers.

Rust
let numbers: [i32; 3] = [[1], 2, 3];
Drag options to blanks, or click blank then click option'
A"one"
B3.0
Ctrue
D1
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a string or float instead of an integer.
4fill in blank
hard

Fill both blanks to create a vector and add an element to it.

Rust
let mut v = Vec::new();
v.[1](10);
let first = v.[2](0);
Drag options to blanks, or click blank then click option'
Apush
Bget
Cpop
Dinsert
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using pop to add elements or insert without index.
5fill in blank
hard

Fill all three blanks to create a tuple, destructure it, and print the values.

Rust
let [1] = ("Rust", 2024);
let (language, year) = [2];
println!("{} was released in {}", [3], year);
Drag options to blanks, or click blank then click option'
Ainfo
Clanguage
Ddata
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using different variable names for the tuple and destructuring.
Printing the tuple variable instead of the destructured value.