Rust Programming Language MCQs

Rust Programming Language MCQs

Answer these 30 Rust Programming Language MCQs and assess your grip on the subject of Rust Programming Language.
Scroll below and get started!

1: The ioctl() function is used to interact with which of the following?

A.   Disk Drives

B.   Virtual TTY lines

C.   Special character devices

A.   Removes the file from its directory

B.   Sets the file’s Inode count to one (1)

C.   Moves the file in from one directory to another

3: Which of the following is the result of a process calling UNIX exec()?

A.   A new process is created

B.   The process becomes executable

C.   The process is completely overwritten

D.   The process blocks waiting for another process to run

4: CORBA's DII allows a client to do which one of the following?

A.   Generate client-side stubs for interfaces

B.   Dynamically link with cross-platform libs

C.   Connect with proxy objects across platforms

D.   Discover new objects and interfaces at runtime

5: The result of calling kill(6003, 0) is which of the following?

A.   Process 6003 terminates

B.   The signal 0 is sent to process 6003

C.   The signal 6003 is sent to process 0

D.   The existence of process 6003 is checked

6: Which of the following techniques can help keep system programs secure?

A.   Encrypt every process’ executable

B.   Setuid important processes to the root user

C.   Limit system calls to administrators

D.   Check all system calls for error conditions

7: Which of the following could the fork() command return to the child process?

A.   -1

B.   2054

C.   19456

D.   0

8: Which of the following is correct for the standard file descriptors that are automatically opened in UNIX?

A.   STDIN_FILENO = 0, STDOUT_FILENO = 1, STDERR_FILENO = 2

B.   STDOUT_FILENO = 0, STDERR_FILENO = 1, STDERR_FILENO = 2

C.   STDERR_FILENO = 0, STDOUT_FILENO = 1, STDIN_FILENO = 2

D.   STDIN_FILENO = 0, STDERR_FILENO = 1, STDOUT_FILENO = 2

9: When a new process is created using fork(), which of the following describes the state of open file descriptors?

A.   The child inherits the parent’s

B.   The child overwrites the parent’s

C.   The child has distinct copies of the parent’s

D.   The child always has an empty set of closed descriptors

10: An orphan process occurs as a result of which of the following conditions?

A.   Parent and child process terminate simultaneously

B.   Child process terminates before its parent process

C.   Parent process terminates before its child process

11: Race conditions are caused by which of the following conditions in a multi threaded system?

A.   Proper program function requires all threads to run quickly

B.   Proper program function requires that all threads run at the same speed

C.   Proper program function is dependent on the execution sequence and timing of each thread

12: You want to listen on a port for some user-defined data stream. Would you use port 80?

A.   No, it is a 'well-defined' or reserved port.

B.   No, it is best to use three or four digit port numbers.

C.   Yes, it is as good as any other port number.

D.   Yes, it is best to use low numbers for port numbers

13: The purpose of the poll() and select() system calls is to perform which of the following functions?

A.   Watch a set of file descriptors to see which are ready

B.   Frequently check email and other network services

C.   Sample system process information for use by the top command

14: Which of the following provides the most random seed source for a pseudo random number generator?

A.   C rand() function

B.   /dev/random

15: Which type cast preserves the mathematical value in all cases?

A.   I64 as i32

B.   Usize as u64

C.   I32 as i64

D.   F64 as f32

16: Which choice is not a scalar data type?

A.   Integer

B.   Float

C.   Boolean

D.   Tuple

17: _ cannot be destructured.

A.   Traits

B.   Tuples

C.   Enums

D.   Structs

18: Which cargo command checks a program for error without creating a binary executable?

A.   Cargo --version

B.   Cargo init

C.   Cargo build

D.   Cargo check

A.   It's creating a pointer on the heap that points to a value on the stack.

B.   It's creating a pointer on the stack that points to a value on the heap.

C.   It's creating a memory guard around values to prevent illegal access.

D.   It's an abstraction that refers to ownership.

20: Using the ? operator at the end of an expression is equivalent to _.

A.   A match pattern that branches into True or False

B.   Calling ok_error()

C.   Calling panic!()

D.   A match pattern that may result an early return

21: Which is valid syntax for defining an array of i32 values?

A.   Array::with_capacity(10)

B.   [i32]

C.   Array::new(10)

D.   [i32; 10]

22: The smart pointers Rc and Arc provide reference counting. What is the API for incrementing a reference count?

A.   .add()

B.   .incr()

C.   .clone()

D.   .increment()

23: What happens when an error occurs that is being handled by the question mark (?) operator?

A.   The error is reported and execution continues.

B.   An exception is raised. The effect(s) of the exception are defined by the error! macro.

C.   The program panics immediately.

D.   Rust attempts to convert the error to the local function's error type and return it as Result::Err. If that fails, the program panics.

A.   /*

B.   #

C.   //!

D.   //

25: In matching patterns, values are ignored with _.

A.   .ignore()

B.   An underscore (_)

C.   ..

D.   Skip

26: Defining a _ requires a lifetime parameter.

A.   Function that ends the lifetime of one of its arguments

B.   Struct that contains a reference to a value

C.   Function with a generic argument

D.   Struct that contains a reference to a boxed value

27: Which statement about lifetimes is false?

A.   Lifetimes were redundantly specified in previous version of Rust.

B.   Lifetimes are specified when a struct is holding a reference to a value.

C.   Lifetimes are specified when certain values must outlive others.

D.   Lifetimes are always inferred by the compiler.

28: When used as a return type, which Rust type plays a similar role to Python's None, JavaScript's null, or the void type in C/C++?

A.   !

B.   None

C.   Null

D.   ()

29: Which statement about the Clone and Copy traits is false?

A.   Copy is enabled for primitive, built-in types.

B.   Without Copy, Rust applies move semantics to a type's access.

C.   When using Clone, copying data is explicit.

D.   Until a type implements either Copy or Clone, its internal data cannot be copied.

30: What smart pointer is used to allow multiple ownership of a value in various threads?

A.   Arc

B.   Box

C.   Both Arc and Rc are multithread safe.

D.   Rc

31: Which types are not allowed within an enum variant's body?

A.   Zero-sized types

B.   Structs

C.   Trait objects

D.   Floating-point numbers

32: Your application requires a single copy of some data type T to be held in memory that can be accessed by multiple threads. What is the thread-safe wrapper type?

A.   Mutex>

B.   Rc>

C.   Arc>

D.   Mutex>

33: Which choice is not valid loop syntax?

A.   Loop

B.   For

C.   While

D.   Do

34: Which statement about enums is false?

A.   Enums are useful in matching patterns.

B.   Option is an enum type.

C.   Enum variants can have different types with associated data.

D.   The term enum is short for enummap

35: What does an underscore (_) indicate when used as pattern?

A.   It matches everything.

B.   It matches underscores.

C.   It matches any value that has a length of 1.

D.   It matches nothing.

36: What is a safe operation on a std::cell:UnsafeCell?

A.   A &mut T reference is allowed. However it may not cpexists with any other references. and may be created only in single-threaded code.

B.   UnsafeCell provides thread-safety. Therefore, creating &T references from multiple threads is safe.

C.   The only safe operation is the .get() method, which returns only a raw pointer.

D.   Non. UnsafeCell only allows code that would otherwise need unsafe blocks to be written in safe code.

37: Generics are useful when you _.

A.   Need to reduce code duplication by concretizing values and restricting parameters in functions

B.   Need to reduce code duplication by abstracting values further, such as in function parameters

C.   Need a supertrait

D.   Are not sure if you need a specific kind of trait

38: How do you create a Rust project on the command-line?

A.   Cargo new

B.   Rustup init

C.   Cargo start

D.   Rust new-project