Skip to content
- What is the main purpose of Rust?
- A) Web Development
- B) Systems Programming
- C) Game Development
- D) Data Science
- Which keyword is used to define a variable in Rust?
- A) let
- B) var
- C) const
- D) define
- Which of the following is a valid way to create a function in Rust?
- A) function my_func() {}
- B) def my_func() {}
- C) fn my_func() {}
- D) func my_func() {}
- What does the
mut keyword signify in Rust?
- A) Immutable variable
- B) Mutable variable
- C) Constant variable
- D) Read-only variable
- What indicates a block of code in Rust?
- A) Parentheses
- B) Curly Braces
- C) Square Brackets
- D) Angle Brackets
- How do you create an array in Rust?
- A) let arr = [1, 2, 3];
- B) let arr = (1, 2, 3);
- C) let arr = {1, 2, 3};
- D) let arr: [1, 2, 3];
- Which of the following is NOT a primitive type in Rust?
- A) i32
- B) f64
- C) String
- D) bool
- What is the output of
println!("Hello, {}!", "World");?
- A) Hello, World!
- B) “Hello, World!”
- C) Hello, World
- D) “Hello, {}!”
- Which trait is used for formatting strings in Rust?
- A) Format
- B) Display
- C) Stringify
- D) Print
- How can you define a struct in Rust?
- A) struct MyStruct {}
- B) structure MyStruct {}
- C) MyStruct = struct {}
- D) define MyStruct {}
- What is the purpose of the
match keyword in Rust?
- A) To create cases
- B) To compare values
- C) To handle control flow
- D) To declare variables
- How do you define an enum in Rust?
- A) enum MyEnum {}
- B) enumeration MyEnum {}
- C) MyEnum = enum {}
- D) define MyEnum {}
- Which command is used to compile a Rust program?
- A) rust build
- B) rustc
- C) cargo run
- D) compile rust
- What is the purpose of
Cargo in Rust?
- A) Package manager
- B) Library manager
- C) Compiler
- D) Framework
- Which symbol is used for comments in Rust?
- What does the
; signify in Rust?
- A) End of statement
- B) Declaration
- C) Separator
- D) Comment
- What is the default return type of a function in Rust?
- A) i32
- B) ()
- C) null
- D) void
- Which of the following is used to handle errors in Rust?
- A) Result
- B) Exception
- C) Error
- D) Issue
- How do you declare a constant in Rust?
- A) const MY_CONST: i32 = 10;
- B) let MY_CONST: i32 = 10;
- C) constant MY_CONST: i32 = 10;
- D) define MY_CONST: i32 = 10;
- What are lifetimes used for in Rust?
- A) Compile-time checking
- B) Memory management
- C) Type safety
- D) Both A and B
- How is string concatenation done in Rust?
- A) “hello” + “world”
- B) format!(“hello {}”, “world”)
- C) “hello”.concat(“world”)
- D) Both B and C
- Which of the following is NOT a collection type in Rust?
- A) Vectors
- B) HashMaps
- C) Strings
- D) Arrays
- What does the
#[derive(Debug)] attribute do in Rust?
- A) Implements default characteristics
- B) Allows for debug formatting
- C) Automatically generates functions
- D) All of the above
- How do you handle multiple ownership in Rust?
- A) Using closures
- B) Using smart pointers
- C) Using references
- D) All of the above
- Which operator is used for pattern matching in Rust?
- A) in
- B) match
- C) ==
- D) switch
- What is the purpose of the
self keyword?
- A) Referring to a module
- B) Referring to the current instance
- C) Referring to a variable
- D) Referring to lifetime
- How can mutable references be created?
- A) &mut variable
- B) variable.mutable()
- C) &variable
- D) mut &variable
- How do you access a value from a HashMap?
- A) map[key]
- B) map.get(key)
- C) map.get_value(key)
- D) Both A and B
- What is a closure in Rust?
- A) A function that captures its environment
- B) A struct
- C) An enum
- D) A type
- Which keyword is used to define a trait in Rust?
- A) trait
- B) interface
- C) type
- D) struct
- What is the size of a Rust
bool type?
- A) 1 byte
- B) 4 bytes
- C) 8 bytes
- D) 2 bytes
- Which function is used to create a new thread?
- A) spawn()
- B) thread::new()
- C) std::thread::spawn()
- D) create_thread()
- What is
unsafe code in Rust?
- A) Code that may result in an error
- B) Code that cannot be checked by the compiler
- C) Code that requires additional permissions
- D) Code that uses obsolete features
- Which macro is used for benchmarking in Rust?
- A) #[bench]
- B) #[test]
- C) #[macro]
- D) #[profile]
- How do you create an iterator from a collection?
- A) collection.iter()
- B) collection.new_iterator()
- C) iteration(collection)
- D) create_iterator(collection)
- What does
Option<T> signify in Rust?
- A) A mandatory value
- B) An optional value
- C) A default value
- D) None of the above
- How can you convert a string to an integer in Rust?
- A) string.parse::<i32>()
- B) string.to_int()
- C) string.convert(i32)
- D) parse(string, i32)
- What is the purpose of the
unsafe keyword in Rust?
- A) To write low-level code
- B) To bypass borrowing rules
- C) To facilitate raw pointers
- D) All of the above
- Which operator is used for equality checking in Rust?
- How do you create a loop in Rust?
- A) loop {}
- B) while true {}
- C) for infinity {}
- D) Both A and B
- Which of these is a feature of Rust’s ownership model?
- A) No garbage collection
- B) Multiple ownership
- C) Shared mutable state
- D) Reference cycles
- How do you define a variable with a specific type?
- A) let var: Type;
- B) var: Type = value;
- C) Type var;
- D) var as Type;
- What does
panic!() do in Rust?
- A) Causes graceful exit
- B) Triggers a runtime error
- C) Handles exceptions
- D) Restarts the program
- Which crate is used for asynchronous programming in Rust?
- A) async-std
- B) futures
- C) tokio
- D) All of the above
- How is a hashmap declared in Rust?
- A) let mut map = HashMap::new();
- B) let map = HashMap {};
- C) let mut map: HashMap = {};
- D) map = HashMap.new();
- What would
vec![1, 2, 3] create in Rust?
- A) An array
- B) A tuple
- C) A vector
- D) A hashmap
- How can errors be propagated in Rust?
- A) Using the ? operator
- B) Using Result<T, E>
- C) Both A and B
- D) Using exceptions
- What does
std::fs::read_to_string() do in Rust?
- A) Reads binary data
- B) Reads a file and returns its contents as a string
- C) Writes data to a file
- D) Creates a string variable
- How do you implement a trait for a struct in Rust?
- A) impl Trait for Struct {}
- B) structure Struct implements Trait {}
- C) Trait: Struct {}
- D) Struct implements Trait {}
- Which crate is commonly used for testing in Rust?
- A) test
- B) rand
- C) tokio
- D) reqwest