Olete.in
Articles
Mock Tests
🧪 Rust (programming language) MCQ Quiz Hub
Rust Programming Language (MCQ)
Choose a topic to test your knowledge and improve your Rust (programming language) skills
1. Which keyword is used to define a variable in Rust
const
let
f32
mul
2. Which of the following is immutable by default in Rust but can be made mutable
Depends on usage
user defined object
const
variable
3. In OOP in Rust, which keyword is used to define Interfaces?
pub
impl
trait
fn
4. pub is used to define public in Rust. Are the data members in the structure public or private
private
public
depends on function
undefined
5. What is the impl keyword used in Rust?
For Interfaces
For Inheritance
Define a class
Implement functionality on types
6. Which code statement in Rust is used to define a BTreeMap object?
let mut btm = BTreeMap::new();
let btm = BTreeMap::new();
BTreeMap btm = std::collections::BTreeMap::new();
BTreeMap btm = BTreeMap.new();
7. Which command is used to compile a Rust code?
rustc code.rs
code
gcc code.rs
gcrust code.rs
8. Among const and static in Rust, which one has low memory requirement?
same for both
static
depends on datatype
const
9. Rust is known to be memory safe. Which feature is the main reason for the memory safety of Rust?>
ownership
borrowing
reference
lifetimes
10. Arbitrary casting is one of the most dangerous feature of Rust. Which keyword is used for it?
as
(data_type) variable
static
transmute
11. To support Dynamic Sized variables, what should we use in place of "f32"?
?Sized
list all data-types
Not supported in Rust
Use array
12. Raw pointers are unsafe pointers in Rust. What is the main use of Raw pointers in Rust?
C type implementation
Low level memory control
Get address of variables
Foreign Function Interface
13. In Rust, unsafe function and block allows 3 features. Which one feature is not allowed in Rust "unsafe" ?
Call unsafe functions
Dereference a raw pointer
turn off the borrow checker
Access or update a static mutable variable
14. What is the use of "type" keyword in Rust?
User defined data type
dynamic sized datatype
template
alias of another type
15. What is "Drop" in Rust used for?
option4
Run code and drop it if error comes
Run code as multi-threaded
Run code when variable is out of scope
16. In Rust, how is a macro from the above Rust code snippet used?
foo!()
#foo
foo
foo(x)
17. What is the predefined macro "unreachable!" in Rust used for?
warning if code not executed
un-implemented code snippet
sample code for unexpect path
code should never execute
18. Which library does Rust use for memory allocation?
mimalloc
jemalloc
ptmalloc
tcmalloc
19. Who designed Rust from scratch in 2006?
Graydon Hoare
David Flanagan
Yukihiro Matsumoto
Guido van Rossum
20. What is Cargo in Rust?
Build system
Build system and package manager
Collection of Rust libraries
Package manager
21. Does Rust guarantee Tail Call Optimization?
Depends on recursion
On using safe block
No
Yes
22. In a function declaration, we can use &self, self and &mul. When is self used?
Value consumed by function
Read only reference to value needed
Value mutated by function
Refer to local variable
23. When is unwrap() used in Rust?
For loop optimizations
To make code linear
Compiler optimizations
For debugging
24. What is the version of the latest Rust release (As of late 2021)?
1.31.1
2.0.0
1.55.0
1.1.0
25. Which company controls Rust Programming Language?
LLVM
Mozilla
Google
The Rust Foundation
26. Is Rust an Object Oriented Programming (OOP) Language?
Yes, it is OOP
No, it is multi paradigm
No, it is Procedural
No, it is functional
27. There are many string data types in Rust like Slice, OsStr, str, CStr, Owned, String, OsString and CString. Which one is a primitive data type in Rust?
Owned
CString
str
String
28. Does Rust support "Move Constructors"
yes
Only for primitive data type
Yes, if Move() is implemented
No
29. Is Rust Garbage Collected by default?
Only when pointers are used
Depends on memory usage
No
Yes
30. How to disable warnings in Rust about unused code segments?
what_is_this()
std::any::type_name
variable.type_name()
std::intrinsic::type_name
31. How to print data type of a variable in Rust?
what_is_this()
std::any::type_name
variable.type_name()
std::intrinsic::type_name
32. How to convert a String to an Integer (int) in Rust?
my_string.parse()
int(my_string)
my_string.to_int()
my_string.parse().unwrap();
33. There are 3 different ways to return an iterator in Rust: into_itr, itr and itr_mul. What is the yield of the returned iterator for itr?
&T
T
&mut T
mut T
34. Rust supports many tools officially like Rustup and Rustfmt. What is Clippy tool in Rust?
Code cleanup
Linter
Code formatter
Code compressor
35. What will be the output of the above Rust code?
54
66
Compilation error
Runtime error
36. The above code outputs the size of variable a. What is the output (in bytes)?
4
2
o
1
37. What is the output of the above code?
32
undefined
44
21
38. From previous question, we know increment and decrement operators does not exist in Rust. What will be the output of the above code?
2
option3
option2
option4
39. Which function in Rust helps to clean heap memory?
flush
deallocate
clean
Drop
40. From which code does the compilation of a Rust project begin
cargo root
carte root
root
root use
41. In a Rust code, what does & denote in a function signature?
Reference of parameter
type of parameter
Pointer of parameter
Address of parameter
42. In Rust, which keyword is used to define a boolean?
bool
Boolean
boolean
:boolean
43. What bracket is used as a placeholder in Rust?
()
{}
[]
::()::
44. Which is the following is a correct Rust syntax?
let slice = &s[0..5];
let slice = s[0->5];
let slice = &s[0->5];
let slice = s[0..5];
Submit