Rust Aptitude Test

This post presents a Rust programming aptitude test with 25 multiple-choice questions for beginners. These beginner-level MCQ questions cover essential aspects of Rust programming and are designed to test fundamental understanding and basic syntax.

1. What is Rust primarily known for?

a) Web development
b) Memory safety without garbage collection
c) Mobile applications
d) Game development

2. Which of the following is used to declare a variable in Rust?

a) var name = “Rust”;
b) let name = “Rust”;
c) variable name = “Rust”;
d) let mut name = “Rust”;

3. What is the file extension used for Rust source files?

a) .rs
b) .ru
c) .rst
d) .rust

4. How do you declare a constant in Rust?

a) const SIZE: i32 = 100;
b) let SIZE: i32 = 100;
c) constant SIZE: i32 = 100;
d) define SIZE: i32 = 100;

5. Which keyword is used to define a function in Rust?

a) func
b) def
c) function
d) fn

6. What is the purpose of the ownership model in Rust?

a) To facilitate dynamic memory allocation
b) To manage memory safety in the absence of a garbage collector
c) To increase performance by removing pointers
d) To simplify code readability

7. How do you include external crates in a Rust project?

a) use crate_name;
b) include crate_name;
c) import crate_name;
d) extern crate crate_name;

8. Which macro is used for printing output to the console in Rust?

a) print!
b) println!
c) console!
d) output!

9. What does the match statement do in Rust?

a) Error handling
b) Variable declaration
c) Pattern matching
d) Looping through items

10. What is the correct way to define a new struct in Rust?

a) struct Person { name: String, age: u32 }
b) new struct Person { name: String, age: u32 }
c) create struct Person { name: String, age: u32 }
d) define struct Person { name: String, age: u32 }

11. What type of error handling is commonly used in Rust?

a) Exceptions
b) Return codes
c) Result and Option types
d) Break and continue

12. What is the use of Cargo in Rust?

a) Memory management
b) Compiling and managing dependencies
c) Data structuring
d) Networking

13. How do you define an immutable variable in Rust?

a) var x = 5;
b) mut x = 5;
c) let x = 5;
d) const x = 5;

14. What is the default integer type in Rust?

a) i32
b) i64
c) int
d) int32

15. How do you create an enum in Rust?

a) enum Color { Red, Green, Blue }
b) create enum Color { Red, Green, Blue }
c) define enum Color { Red, Green, Blue }
d) new enum Color { Red, Green, Blue }

16. How can you manage multiple threads in Rust?

a) Rust does not support multithreading
b) Using the thread crate
c) By using async and await
d) Using the std::thread module

17. What is a trait in Rust?

a) A feature that defines a set of methods and associated types
b) A built-in function for managing memory
c) A package management tool
d) A special type of constant

18. How do you handle errors returned by functions in Rust?

a) Using try and catch
b) Using the Result type and the match statement
c) Ignoring them
d) Using exceptions

19. What does the & symbol signify in Rust?

a) Pointer
b) Array
c) Reference
d) Memory allocation

20. How do you update a dependency in a Rust project managed by Cargo?

a) cargo update
b) cargo upgrade
c) cargo manage –update
d) cargo refresh

21. What is Rust’s safety feature that prevents data races?

a) Ownership
b) Type checking
c) Encapsulation
d) Dynamic binding

22. Which keyword is used to bring a library into scope?

a) import
b) include
c) use
d) lib

23. What is the purpose of the mod keyword in Rust?

a) Modify existing functions
b) Declare a module
c) Modify variable values
d) Perform modular arithmetic

24. How do you print a variable in Rust?

a) print!(x)
b) println!(x)
c) println!(“{}”, x)
d) println!(print x)

25. What is Rust’s approach to null values?

a) Null pointers
b) The Option enum
c) Use of undefined
d) Nullified references

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top