1. What is Rust?
a) A programming language
b) A type of fungus
c) A database management system
d) A web framework
Answer: a) A programming language
2. Which company developed Rust?
a) Google
b) Mozilla
c) Microsoft
d) Facebook
Answer: b) Mozilla
3. Which of the following is a key feature of Rust?
a) Automatic memory management
b) Garbage collection
c) Static typing
d) Dynamic typing
Answer: c) Static typing
4. What is Rust's main focus when it comes to safety?
a) Runtime safety
b) Compile-time safety
c) Type safety
d) Memory safety
Answer: b) Compile-time safety
5. Which of the following is not a primitive data type in Rust?
a) int
b) bool
c) char
d) string
Answer: d) string
6. In Rust, what keyword is used to define a function?
a) def
b) func
c) fn
d) function
Answer: c) fn
7. What does the mut keyword indicate in Rust?
a) A mutable reference
b) An immutable reference
c) A macro
d) A type definition
Answer: a) A mutable reference
8. Which of the following is the correct way to create a new instance of a struct in Rust?
a) let new_struct = Struct;
b) let new_struct = struct.new();
c) let new_struct = Struct::new();
d) let new_struct = struct::new;
Answer: c) let new_struct = Struct::new();
9. What is Rust's ownership system designed to prevent?
a) Concurrency bugs
b) Memory leaks
c) Compilation errors
d) Runtime errors
Answer: b) Memory leaks
10. Which macro is used for printing to the console in Rust?
a) println!
b) print!
c) console.log!
d) cout
Answer: a) println!
11. What is Rust's package manager called?
a) Cargo
b) RustPM
c) Cargo.toml
d) rustup
Answer: a) Cargo
12. Which of the following is not a valid Rust comment style?
a) // This is a comment
b) /* This is a comment /
**c) <!-- This is a comment -->*
d) /// This is a doc comment
Answer: c) <!-- This is a comment -->
13. In Rust, which of the following keywords is used for branching and decision making?
a) when
b) switch
c) if
d) choose
Answer: c) if
14. What does the match keyword in Rust allow you to do?
a) Create a new function
b) Define a loop
c) Perform pattern matching
d) Define a struct
Answer: c) Perform pattern matching
15. Which keyword is used to define an enum in Rust?
a) type
b) enum
c) struct
d) define
Answer: b) enum
16. What is Rust's approach to handling null or nil values?
a) Rust allows null values
b) Rust uses Option and Result types to handle absence or errors
c) Rust uses a special keyword "nil"
d) Rust raises exceptions for null values
Answer: b) Rust uses Option and Result types to handle absence or errors
17. What does the std::collections::HashMap provide in Rust?
a) A list of items
b) A mapping of keys to values
c) A stack data structure
d) A set of integers
Answer: b) A mapping of keys to values
18. Which module is used for file I/O operations in Rust?
a) io::file
b) std::fs
c) file::io
d) io::std
Answer: b) std::fs
19. What is the purpose of the use keyword in Rust?
a) Import modules and symbols
b) Define custom macros
c) Declare global variables
d) Create new types
Answer: a) Import modules and symbols
20. What is the syntax for creating a string slice in Rust?
a) "Hello, World"
b) String::from("Hello, World")
c) &"Hello, World"
d) str("Hello, World")
Answer: c) &"Hello, World"
21. How does Rust handle concurrency and parallelism?
a) Using threads and channels
b) Using mutexes and semaphores
c) Using global variables
d) Using callbacks
Answer: a) Using threads and channels
22. What is the purpose of the async keyword in Rust?
a) To define asynchronous functions
b) To handle exceptions
c) To define macros
d) To define closures
Answer: a) To define asynchronous functions
23. Which of the following is an ownership rule in Rust?
a) There can be multiple mutable references to the same data
b) There can be only one mutable reference to a piece of data at a time
c) There are no restrictions on references to data
d) Data can be mutated without explicit permissions
Answer: b) There can be only one mutable reference to a piece of data at a time
24. What does the self keyword represent in a method definition in Rust?
a) The current module
b) The class instance or structure itself
c) The superclass
d) The function itself
Answer: b) The class instance or structure itself
25. Which crate in Rust is commonly used for JSON serialization and deserialization?
a) serde_json
b) json_serial
c) rust_json
d) json_parser
Answer: a) serde_json
26. Which keyword is used to perform an early return from a function in Rust?
a) stop
b) exit
c) return
d) break
Answer: c) return
27. In Rust, which function is used to convert a string to an integer?
a) to_int
b) str_to_int
c) parse
d) str_parse
Answer: c) parse
28. What does the drop method do in Rust?
a) It releases memory associated with a value
b) It panics if a condition is not met
c) It converts a value to a string
d) It appends a value to a collection
Answer: a) It releases memory associated with a value
29. Which of the following is a valid way to spawn a new thread in Rust?
a) new_thread()
b) spawn_thread()
c) std:🧵:spawn()
d) start_thread()
Answer: c) std:🧵:spawn()
30. What is the purpose of the as keyword in Rust?
a) To cast between data types
b) To define an alias for a function
c) To define an array
d) To define a struct
Answer: a) To cast between data types
Top comments (0)