Bird
Raised Fist0
Rustprogramming~10 mins

What is Rust - Interactive Quiz & Practice

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

Complete the code to print "Hello, Rust!" to the console.

Rust
fn main() {
    println!([1]);
}
Drag options to blanks, or click blank then click option'
A"Hello, Rust!"
BHello, Rust!
C'Hello, Rust!'
Dprintln!("Hello, Rust!")
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting the double quotes around the string
Using single quotes instead of double quotes
Passing the text without quotes
2fill in blank
medium

Complete the code to declare a variable named age with the value 30.

Rust
fn main() {
    let [1] = 30;
}
Drag options to blanks, or click blank then click option'
Avar age
Bconst age
Cage
Dlet age
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Including let again inside the blank
Using var which is not Rust syntax
Using const which requires a type
3fill in blank
hard

Fix the error in the function signature to accept a string slice parameter named name.

Rust
fn greet([1]: &str) {
    println!("Hello, {}!", name);
}
Drag options to blanks, or click blank then click option'
Aname: &str
Bname: String
Cname
D&name
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Writing only the variable name without type
Using String instead of &str
Using &name which is invalid syntax
4fill in blank
hard

Fill both blanks to create a vector of numbers from 1 to 5 and print its length.

Rust
fn main() {
    let mut numbers = Vec::[1]();
    for i in 1..=[2] {
        numbers.push(i);
    }
    println!("Length: {}", numbers.len());
}
Drag options to blanks, or click blank then click option'
Anew
B5
Cwith_capacity
D10
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using with_capacity without a number
Looping beyond 5
Not initializing the vector properly
5fill in blank
hard

Fill all three blanks to create a hash map, insert a key-value pair, and print the value for the key.

Rust
use std::collections::HashMap;

fn main() {
    let mut map = HashMap::[1]();
    map.[2]("color", "blue");
    println!("Color: {}", map.get("color").[3]());
}
Drag options to blanks, or click blank then click option'
Anew
Binsert
Cunwrap
Dpush
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using push which is not a HashMap method
Forgetting to unwrap the Option returned by get
Not making the map mutable

Practice

(1/5)
1. What is Rust primarily known for?
easy
A. A fast and safe programming language
B. A type of database
C. A web browser
D. A mobile operating system

Solution

  1. Step 1: Understand Rust's main features

    Rust is designed to be fast and safe, focusing on preventing bugs.
  2. Step 2: Compare options with Rust's purpose

    Only A fast and safe programming language describes Rust as a fast and safe programming language.
  3. Final Answer:

    A fast and safe programming language -> Option A
  4. Quick Check:

    Rust = fast and safe language [OK]
Hint: Rust is a language, not software or hardware [OK]
Common Mistakes:
  • Confusing Rust with a database
  • Thinking Rust is a browser
  • Mixing Rust with operating systems
2. Which of the following is the correct way to declare a variable in Rust?
easy
A. int x = 5;
B. var x = 5;
C. let x = 5;
D. x := 5;

Solution

  1. Step 1: Recall Rust variable declaration syntax

    Rust uses the keyword let to declare variables.
  2. Step 2: Check each option

    Only let x = 5; uses let correctly; others use syntax from other languages.
  3. Final Answer:

    let x = 5; -> Option C
  4. Quick Check:

    Rust variables start with let [OK]
Hint: Rust uses 'let' to declare variables [OK]
Common Mistakes:
  • Using var instead of let
  • Using type declarations like int
  • Using := which is Go syntax
3. What will the following Rust code print?
fn main() {
    let x = 10;
    let y = 20;
    println!("{}", x + y);
}
medium
A. 1020
B. Compilation error
C. x + y
D. 30

Solution

  1. Step 1: Understand the code operations

    Variables x and y hold 10 and 20. The code adds them: 10 + 20 = 30.
  2. Step 2: Check the print statement

    The println! macro prints the sum as a number, not concatenated strings.
  3. Final Answer:

    30 -> Option D
  4. Quick Check:

    10 + 20 = 30 [OK]
Hint: Add numbers inside println! to get output [OK]
Common Mistakes:
  • Thinking + concatenates strings
  • Expecting variable names printed
  • Assuming syntax error
4. Identify the error in this Rust code:
fn main() {
    let mut x = 5;
    x = "hello";
    println!("{}", x);
}
medium
A. Cannot assign a string to an integer variable
B. Missing semicolon after println!
C. Variable x should not be mutable
D. println! macro syntax is incorrect

Solution

  1. Step 1: Analyze variable type and assignment

    Variable x is initially an integer (5). Later, it is assigned a string "hello" which is invalid.
  2. Step 2: Check other syntax elements

    Semicolons and println! syntax are correct; mutability is allowed but types must match.
  3. Final Answer:

    Cannot assign a string to an integer variable -> Option A
  4. Quick Check:

    Type mismatch error = Cannot assign a string to an integer variable [OK]
Hint: Variable types cannot change after declaration [OK]
Common Mistakes:
  • Ignoring type mismatch
  • Thinking mut allows any type
  • Assuming println! needs semicolon fix
5. You want to write a Rust program that safely handles user input and prevents bugs before running. Which feature of Rust helps achieve this?
hard
A. Garbage collection like Java
B. Ownership and borrowing system
C. Dynamic typing for flexibility
D. Automatic memory allocation without checks

Solution

  1. Step 1: Understand Rust's safety features

    Rust uses ownership and borrowing rules to manage memory safely at compile time.
  2. Step 2: Compare with other options

    Rust does not use garbage collection or dynamic typing; it enforces strict checks before running.
  3. Final Answer:

    Ownership and borrowing system -> Option B
  4. Quick Check:

    Rust safety = ownership and borrowing [OK]
Hint: Rust's safety comes from ownership rules [OK]
Common Mistakes:
  • Confusing Rust with garbage collected languages
  • Thinking Rust is dynamically typed
  • Ignoring ownership concept
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard