Rust

Ownership & Borrowing

Ownership rules, move semantics, borrowing (&T, &mut T), lifetimes, dangling references

22 mülakat soruları·
Junior
1

What is ownership in Rust?

Cevap

Ownership is a fundamental system in Rust that guarantees memory safety without a garbage collector. Each value has a single owner, and memory is automatically freed when the owner goes out of scope. This system prevents data races and use-after-free errors at compile time.

2

How many owners can a value have in Rust?

Cevap

In Rust, a value can only have one owner at a time. This is the first rule of ownership. When ownership is transferred (move), the previous owner can no longer access the value. This rule ensures that no two parts of the code can modify or free the same memory.

3

What happens when a variable goes out of scope in Rust?

Cevap

When a variable goes out of scope, Rust automatically calls the drop function which frees the memory. This behavior is deterministic and predictable, unlike garbage collectors that free memory non-deterministically. This pattern is called RAII (Resource Acquisition Is Initialization).

4

What is a move in Rust?

5

Which types implement the Copy trait in Rust?

+19 mülakat soruları

Bir sonraki mülakatın için Rust'de uzmanlaş

Tüm sorulara, flashcards'a, teknik testlere, code review alıştırmalarına ve mülakat simülatörlerine eriş.

Ücretsiz başla