Olete.in
Articles
Mock Tests
🧪 Rust (programming language) MCQ Quiz Hub
Rust Multiple Choice Questions
Choose a topic to test your knowledge and improve your Rust (programming language) skills
1. Who designed Rust?
Doug Cutting
JetBrains
Graydon Hoare
Robert Griesemer
2. Rust is syntatically similar to which programming language?
C++
Python
C Sharp
Java
3. Which among the following is permitted by rust?
Null Pointers
let keyword
Data Races
Automated Garbage Collectors
4. Which among the following is not a valid keyword in Rust?
mut
impl
let
var
5. Which keyword is used to write a function in rust?
fn
function
func
f
6. What does ::new indicates?
static method
abstract method
final method
main method
7. What are the result types in Rust?
structure
enumerations
class
union
8. Which of the following are Result variants in Rust?
success and err
Success and Error
Ok and Error
Ok and Err
9. Which method is defined on Result types?
main
expect
handle
init
10. Which brackets are used as placeholder in rust?
{ }
( )
[ ]
< >
11. Constants cant be defined in which scope
Global
Local
Method
None
12. Rust is
statically typed
dynamically typed
strongly typed
untyped
13. Choose the correct scalar types in Rust
integers, signed numbers, Booleans, and String
integers, floating-point numbers, Booleans, and characters
integers, floating-point numbers and characters
integers, floating-point numbers and Booleans
14. Which keyword is used to specify Boolean type?
boolean
Boolean
bool
bl
15. Which are the two primitive compound types supported by Rust?
tuples and arrays
tuples and lists
lists and arrays
maps and arrays
16. Which of the following is false with respect to tuples?
tup is the keyword used to declare tuples
Tuples have a fixed length
tuple element can be accessed by using dot (.)
every element of a tuple must have the same type
17. Which is not a valid declaration of an array?
let a: [i32; 5] = [1, 2, 3, 4, 5];
let a = [3; 5];
let a: = [3; 5];
let a = [1, 2, 3, 4, 5];
18. Which symbol is used to declare the functions with return values?
::
:
< >
->
19. What is the output of the following program snippet: fn main() { let three = 3; if three { println!("number was three"); } }
number was three
unrecognised keyword println!
error mismatched types
3
20. Which among the following loop is not supported by Rust?
loop
while
for
do while
21. Which among the following is false with respect to ownership rules?
each value in Rust has a variable which is the owner.
There can only be one owner at a time.
When the owner goes out of scope, the value will be dropped.
owner never goes out of scope
22. Which operator allows to use namespace?
::
:
.
!
23. What does the String data type hold in Rust?
a pointer to the memory where String resides and its capacity
a pointer to the memory where String resides, a length, and a capacity
a string value and its length
a string value, a length, and a capacity
24. What does the below statements infer? let s1 = String::from("example"); let s2 = s1;
a copy of the value in s1 is binded to s2
copy the data on the heap that the pointer in string refers to
copy the pointer, the length, and the capacity that are on the stack.
copy the data on the string pool that the pointer in string refers to
25. Which function assists in cleaning up the heap memory in Rust?
drop
deallocate
flush
clean
26. Automatic copying in rust ______
inexpensive in terms of runtime performance
create “deep” copies of your data
hinders runtime performance
All of the above
27. Identify the types which are not Copy in Rust?
char
bool
(i32, i32)
(i32, String)
28. What does & in the function signature of Rust indicate?
type of the parameter
address
pointer
reference
29. When does the data race occur in Rust?
Two or more pointers access the same data at the same time.
At least one of the pointers is being used to write to the data.
There’s no mechanism being used to synchronize access to the data
All of the above
30. Which among the following is not a valid rule for references in Rust?
References must always be valid
one mutable reference
the compiler guarantees that references will never be dangling references
immutable references are not to be used
31. What is the proper notation of Rust's range syntax?
let slice = &s[0..2];
let slice = &s[0-2];
let slice = s[0-2]
let slice = &s[0:2];
32. String literals are
not slices
static
mutable
immutable
33. Which is not true with respect to structs in Rust?
flexible than tuples
order of the data is important to access the values
dot notation is used to specify the value from a struct
key: value pairs to be specified inside { }
34. In Tuple structs
only type of the fields is specified
names associated with their fields to be specified
start with the tuple keyword
cant destructure them into their individual pieces
35. What is the use of unit-like structs?
Useful for generics.
If you don't want to store in the type itself.
behave similar to ().
All of the above
36. Which keyword is used to create a method?
impl
method
fn
no keyword
37. What are associated functions?
defining functions within methods
associated with structs
return a new instance of the struct
cant be used for constructors
38. Which among the following is true with respect to Multiple impl blocks?
Each struct is allowed to have multiple impl blocks
each method in its own impl block
first parameter is always self
All of the above
39. Choose the valid variant of enum in Rust?
can have no data associated with it at all
includes an anonymous struct inside it
includes a single String
All of the above
40. Which among the following is false with respect to Option Enum in Rust?
encode the concept of a value being present or absent
compile checks whether all the cases are handled
prevent bugs
need to bring it into scope explicitly
41. Which is the control flow operator used for pattern matching in Rust?
option
match
control
self
42. Which operator separates the pattern and the code to be executed?
=>
->
::
_
43. Which operator is used as placeholder in Rust for pattern matching?
:
::
->
_
44. Which among the following is not true regarding if let in Rust?
else can be included within if let
if let takes a pattern and an expression separated by an = sign
if let takes a pattern and an expression separated by an => sign
matches one pattern and ignoring the rest
45. Which standard library type helps to use the type system in order to prevent errors in Rust?
Option<T>
Cargo
Crate
Vec<T>
46. Which Cargo feature helps to build, test, and share crates?
match
Packages
Option<T>
Modules
47. Which among the following has a tree of modules that produces a library or executable?
Modules
Crates
Packages
Paths
48. Which helps in controlling the organization, scope and Paths privacy?
Paths
Crates
Modules
Packages
49. What is a way of naming an item, such as a struct, function, or module called?
Crates
Packages
Modules
Paths
50. From which source file does the Rust compiler start?
crate root
cargo root
root
use root
Submit