Rust Interview Questions Hindi mein

Rust कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

Getting Started With Rust

1. How does Rust achieve memory safety?

  1. Manual malloc and free only
  2. A garbage collector running at runtime
  3. Ownership and borrowing rules checked at compile time
  4. Running everything in a virtual machine
जवाब देखें

जवाब: Ownership and borrowing rules checked at compile time

Safety without runtime cost.

पाठ: Why Rust

2. Why does println! end with an exclamation mark?

  1. It is a macro, not a function
  2. It prints in bold
  3. It panics after printing
  4. It runs at compile time only
जवाब देखें

जवाब: It is a macro, not a function

Macros generate code.

पाठ: Hello, World and cargo

3. How do you make a function visible outside its module?

  1. Use the export keyword
  2. Name it with a capital letter
  3. Put it in Cargo.toml
  4. Mark it pub
जवाब देखें

जवाब: Mark it pub

Private by default.

पाठ: Crates, Cargo.toml and Modules

Language Basics

4. What does let x = x * 2; do when x already exists?

  1. Mutates the original x
  2. Shadows x with a new binding
  3. Causes a compile error
  4. Creates a reference to x
जवाब देखें

जवाब: Shadows x with a new binding

Shadowing is not mutation.

पाठ: Variables, Mutability, Shadowing and Types

5. What happens if a match does not cover every possible value?

  1. It returns null
  2. The code does not compile
  3. It panics at runtime only
  4. The last arm is used automatically
जवाब देखें

जवाब: The code does not compile

Matches must be exhaustive.

पाठ: Expressions and Pattern Matching

6. What does a Rust function return if its body ends with an expression without a semicolon?

  1. The first statement
  2. Nothing
  3. An error
  4. The value of that expression
जवाब देखें

जवाब: The value of that expression

Implicit return of the tail expression.

पाठ: Functions and Modules

Ownership, Borrowing and Lifetimes

7. What happens to a String passed by value to a function?

  1. Ownership moves into the function; the caller can no longer use it
  2. It is copied automatically
  3. It becomes a global variable
  4. Nothing; both can use it
जवाब देखें

जवाब: Ownership moves into the function; the caller can no longer use it

Moves transfer ownership.

पाठ: Ownership and Moves

8. What does &mut T allow?

  1. Taking ownership
  2. Sharing the value with any number of readers while mutating
  3. Mutating the borrowed value through an exclusive borrow
  4. Copying the value
जवाब देखें

जवाब: Mutating the borrowed value through an exclusive borrow

Exclusive mutable access.

पाठ: Borrowing With References

9. Which combination of references does Rust allow at the same time?

  1. One shared and one mutable
  2. Many mutable references
  3. Many shared references, or one mutable reference
  4. Unlimited references of any kind
जवाब देखें

जवाब: Many shared references, or one mutable reference

Prevents data races at compile time.

पाठ: The Aliasing Rule

10. Do lifetime annotations make values live longer?

  1. No, they only describe relationships between references
  2. Yes, they extend the lifetime
  3. Yes, they move values to the heap
  4. They disable the borrow checker
जवाब देखें

जवाब: No, they only describe relationships between references

Descriptions, not instructions.

पाठ: Lifetimes

Structs, Enums and Traits

11. Which receiver lets a method modify the struct?

  1. static self
  2. &self
  3. Self
  4. &mut self
जवाब देखें

जवाब: &mut self

Mutation needs an exclusive borrow.

पाठ: Structs and impl Blocks

12. How does Rust represent a value that may be absent?

  1. null
  2. Option<T> with Some or None
  3. An empty string
  4. A special -1 value
जवाब देखें

जवाब: Option<T> with Some or None

Absence is explicit in the type.

पाठ: Enums, Option and Pattern Matching

13. What does `Box<dyn Shape>` enable?

  1. Faster static dispatch
  2. Storing different types that implement Shape in one collection
  3. Avoiding the trait entirely
  4. Garbage collection
जवाब देखें

जवाब: Storing different types that implement Shape in one collection

Trait objects use dynamic dispatch.

पाठ: Traits and Generics

Error Handling

14. What does the ? operator do on an Err value?

  1. Converts it to None silently
  2. Panics
  3. Ignores the error
  4. Returns the error from the current function
जवाब देखें

जवाब: Returns the error from the current function

Early return keeps code flat.

पाठ: Result and the ? Operator

15. Why implement `From<ParseIntError>` for your error type?

  1. So ? can convert a ParseIntError into your error automatically
  2. To print errors in colour
  3. To make errors Copy
  4. Because Display requires it
जवाब देखें

जवाब: So ? can convert a ParseIntError into your error automatically

Conversion powers the ? operator.

पाठ: Custom Error Types

16. Which call avoids a panic when the index might be out of range?

  1. v.unwrap()
  2. v[i]
  3. v.get(i)
  4. panic!()
जवाब देखें

जवाब: v.get(i)

get returns Option.

पाठ: Panics, unwrap and Safe Alternatives

Collections, Iterators and Strings

17. What does String::len() return for non-ASCII text?

  1. The number of words
  2. The number of characters
  3. The number of bytes, which can exceed the number of characters
  4. Always zero
जवाब देखें

जवाब: The number of bytes, which can exceed the number of characters

Strings are UTF-8 bytes.

पाठ: Vec, HashMap and String

18. When does a chain like iter().map(...).filter(...) actually run?

  1. When it is consumed, for example by sum, collect or a for loop
  2. Immediately when map is called
  3. At compile time
  4. Never
जवाब देखें

जवाब: When it is consumed, for example by sum, collect or a for loop

Iterators are lazy.

पाठ: Iterators and Closures

19. Why is &str preferred over &String as a parameter type?

  1. It owns the data
  2. It is mutable
  3. It is always faster to allocate
  4. It accepts both String values and string literals
जवाब देखें

जवाब: It accepts both String values and string literals

More flexible borrowing.

पाठ: String Slices and Array Slices

Fearless Concurrency

20. Why wrap a shared counter in `Arc<Mutex<i32>>`?

  1. To make it immutable
  2. Arc shares ownership across threads and Mutex ensures exclusive access
  3. To avoid using threads
  4. Because i32 cannot be copied
जवाब देखें

जवाब: Arc shares ownership across threads and Mutex ensures exclusive access

Shared ownership plus synchronisation.

पाठ: Threads, Arc, Mutex and Channels

21. What does it mean when a type does not implement Send?

  1. It cannot be printed
  2. It cannot be moved to another thread
  3. It cannot be cloned
  4. It cannot be stored in a Vec
जवाब देखें

जवाब: It cannot be moved to another thread

The compiler blocks unsafe sharing.

पाठ: Send and Sync: Data Races at Compile Time

22. What runs async futures in Rust?

  1. Nothing; futures run when created
  2. The compiler at build time
  3. The operating system automatically
  4. An executor (runtime) such as Tokio
जवाब देखें

जवाब: An executor (runtime) such as Tokio

Futures are lazy until polled.

पाठ: Async Rust at a Glance

Testing, Tooling and a Checklist

23. Why can unit tests in mod tests call private functions?

  1. They are in the same module tree as the code they test
  2. Rust has no private functions
  3. Tests run with root privileges
  4. cfg(test) makes everything public everywhere
जवाब देखें

जवाब: They are in the same module tree as the code they test

Child modules see their parent's private items.

पाठ: Unit Tests With cargo test

24. What does cargo clippy do?

  1. Downloads crates
  2. Formats code
  3. Lints code for common mistakes and non-idiomatic patterns
  4. Profiles performance
जवाब देखें

जवाब: Lints code for common mistakes and non-idiomatic patterns

rustfmt formats; clippy lints.

पाठ: clippy and rustfmt

25. Which item belongs on a Rust review checklist?

  1. Clone every value to avoid borrow errors
  2. Use unwrap everywhere for brevity
  3. Use try_from or checked conversions instead of lossy as casts
  4. Share Rc between threads
जवाब देखें

जवाब: Use try_from or checked conversions instead of lossy as casts

Safe, idiomatic, tested.

पाठ: A Rust Code Review Checklist

← कोर्स पर वापस जाएँ