Rust Programming Basics Quiz
1. What is the official name of the Rust compiler?
RustC
CargoC
Rustling
Rusty Compiler
2. Which command is used to create a new Rust project with Cargo?
`rust new project`
`cargo init project`
`cargo new project`
`create new project`
3. What is the default entry point function for a Rust executable program?
`start()`
`main()`
`run()`
`entry()`
4. How do you print a line to the console in Rust?
`console.log("Hello");`
`print_line("Hello");`
`println!("Hello");`
`echo "Hello";`
5. What is `Cargo` in the Rust ecosystem?
The Rust debugger
The Rust package manager and build system
The Rust standard library
The Rust official IDE
6. Which keyword is used to declare an immutable variable in Rust?
`var`
`let`
`const`
`imm`
7. How do you make a variable mutable in Rust?
By using the `mutable` keyword
By using the `mut` keyword
Variables are mutable by default
By using the `var` keyword
8. What is a "slice" in Rust?
A fixed-size array
A reference to a contiguous sequence of elements in a collection
A dynamically sized vector
A type of string literal
9. Which of these is NOT a primitive integer type in Rust?
`i32`
`u64`
`int`
`isize`
10. What is a "tuple" in Rust?
A collection of elements of the same type
A fixed-size grouping of values of different types
A dynamic array
A structured data type with named fields
11. How do you declare a function in Rust?
`function my_func() {}`
`def my_func():`
`fn my_func() {}`
`func my_func() {}`
12. What does `->` signify in a function signature?
It indicates the function takes no arguments
It indicates the function returns a value of the specified type
It indicates a reference parameter
It's used for type casting
13. Which concept is central to Rust's memory safety guarantees without a garbage collector?
Pointers
Smart pointers
Ownership and borrowing
Reference counting
14. What is the purpose of `if let` expressions in Rust?
To declare a variable and assign it a value
To conditionally assign a value to a mutable variable
To combine `if` and `match` into a less verbose way to handle a single match arm
To create a new scope for a variable
15. How do you create an array in Rust?
`let arr = [1, 2, 3];`
`let arr: array
= [1, 2, 3];`
`let arr = new Array(1, 2, 3);`
`let arr = vec![1, 2, 3];`
16. What does the `&` symbol usually denote in Rust?
A mutable variable
An integer literal
A reference (borrow)
An arithmetic operator
17. What is the type of a string literal, e.g., `"Hello, world!"`?
`String`
`str`
`&String`
`&str`
18. How do you convert a `&str` to a `String`?
Using `to_string()` method
Using `String::from()` function
Both a and b
It's not possible to convert them
19. What is a "struct" in Rust?
A collection type like a vector
A custom data type that lets you name and package together multiple related values
A function that returns a structure
A pointer to a data block
20. Which of these is the correct way to define an `enum`?
`enum Direction { North, East, South, West };`
`enum Direction { North, East, South, West }`
`enum Direction = [North, East, South, West];`
`Enum Direction { North, East, South, West };`
21. What is the primary purpose of the `match` control flow operator?
For simple true/false conditions
To iterate over collections
To compare a value against a series of patterns and execute code based on which pattern matches
To handle potential errors
22. What is an "Option" enum in Rust?
Used for asynchronous operations
Represents the possibility of something being either `Some` value or `None`
A way to define optional function arguments
A type for command-line arguments
23. How do you loop indefinitely in Rust?
`while true {}`
`loop {}`
`for ;; {}`
`infinite {}`
24. What does the `.` operator do when accessing fields of a struct?
It de-references a pointer
It indicates a method call
It allows direct access to named fields of a struct or enum variant
It's used for range iteration
25. Which command compiles and runs a Rust project using Cargo?
`cargo build && cargo exec`
`cargo run`
`rustc main.rs && ./main`
`cargo start`
Submit Quiz
Quiz Results
You scored
0
out of
25
!