# Unsafe Rust (Rust) > Unsafe blocks, raw pointers (*const T, *mut T), FFI, unsafe traits, Undefined Behavior (UB), safety invariants - 20 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: Rust](https://sharpskill.dev/th/technologies/rust/interview-questions.md) ## 1. คีย์เวิร์ดใดที่เปิดใช้งานพลังพิเศษของโหมด unsafe ใน Rust? **คำตอบ** คีย์เวิร์ด unsafe ปลดล็อกความสามารถห้าอย่างที่ถูกห้ามใน safe Rust ได้แก่ การ dereference raw pointers, การเรียกฟังก์ชัน unsafe, การเข้าถึงตัวแปร static แบบ mutable, การ implement unsafe traits และการเข้าถึง field ของ union บล็อกนี้ส่งสัญญาณให้ compiler ทราบว่านักพัฒนารับผิดชอบในการรับประกัน memory safety ## 2. โค้ด unsafe ปลดล็อกความสามารถเพิ่มเติมกี่อย่างเมื่อเทียบกับ safe Rust? **คำตอบ** โหมด unsafe ปลดล็อกความสามารถพอดี 5 อย่าง: การ dereference raw pointer, การเรียกฟังก์ชันหรือเมธอด unsafe, การเข้าถึงหรือแก้ไขตัวแปร static ที่ mutable, การ implement trait unsafe และการเข้าถึงฟิลด์ของ union ทั้ง 5 การดำเนินการนี้คือความแตกต่างเพียงอย่างเดียวระหว่าง safe กับ unsafe Rust ## 3. ไวยากรณ์ที่ถูกต้องในการสร้าง raw pointer แบบ immutable ไปยังตัวแปรใน Rust คืออะไร? **คำตอบ** ไวยากรณ์ในการสร้าง raw pointer แบบ immutable คือ let ptr = &x as *const T ประเภท *const T แทน raw pointer แบบ immutable การสร้าง raw pointer นั้น safe มีเพียง deref เท่านั้นที่ต้องใช้บล็อก unsafe สามารถใช้การ coercion โดยปริยายด้วย let ptr: *const T = &x ได้เช่นกัน ## มีอีก 17 คำถาม - ความแตกต่างระหว่าง *const T กับ *mut T ใน Rust คืออะไร? - เหตุใดการสร้าง raw pointer จึงได้รับอนุญาตใน safe Rust ในขณะที่การ dereference ไม่ได้รับอนุญาต? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Rust อื่นๆ - [พื้นฐาน Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/rust-basics.md): 25 คำถาม, Junior - [Ownership & Borrowing](https://sharpskill.dev/th/technologies/rust/interview-questions/ownership-borrowing.md): 22 คำถาม, Junior - [Structs & Enums](https://sharpskill.dev/th/technologies/rust/interview-questions/structs-enums.md): 20 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/rust/interview-questions/error-handling.md): 18 คำถาม, Junior - [คอลเลกชัน](https://sharpskill.dev/th/technologies/rust/interview-questions/collections.md): 20 คำถาม, Junior - [โมดูลและแพ็กเกจ](https://sharpskill.dev/th/technologies/rust/interview-questions/modules-packages.md): 18 คำถาม, Junior - [Traits](https://sharpskill.dev/th/technologies/rust/interview-questions/traits.md): 22 คำถาม, Mid-Level - [Generics](https://sharpskill.dev/th/technologies/rust/interview-questions/generics.md): 20 คำถาม, Mid-Level - [Lifetimes](https://sharpskill.dev/th/technologies/rust/interview-questions/lifetimes.md): 20 คำถาม, Mid-Level - [Iterators & Closures](https://sharpskill.dev/th/technologies/rust/interview-questions/iterators-closures.md): 22 คำถาม, Mid-Level - [Smart Pointers](https://sharpskill.dev/th/technologies/rust/interview-questions/smart-pointers.md): 22 คำถาม, Mid-Level - [Concurrency Basics](https://sharpskill.dev/th/technologies/rust/interview-questions/concurrency-basics.md): 20 คำถาม, Mid-Level - [async/await](https://sharpskill.dev/th/technologies/rust/interview-questions/async-await.md): 22 คำถาม, Mid-Level - [Testing](https://sharpskill.dev/th/technologies/rust/interview-questions/testing.md): 18 คำถาม, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/th/technologies/rust/interview-questions/cargo-ecosystem.md): 18 คำถาม, Mid-Level - [Pattern Matching](https://sharpskill.dev/th/technologies/rust/interview-questions/pattern-matching.md): 18 คำถาม, Mid-Level - [มาโคร](https://sharpskill.dev/th/technologies/rust/interview-questions/macros.md): 20 คำถาม, Mid-Level - [Serde และการ Serialization](https://sharpskill.dev/th/technologies/rust/interview-questions/serde-serialization.md): 20 คำถาม, Mid-Level - [Trait ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-traits.md): 22 คำถาม, Senior - [Lifetime ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-lifetimes.md): 20 คำถาม, Senior - [Type System](https://sharpskill.dev/th/technologies/rust/interview-questions/type-system.md): 20 คำถาม, Senior - [Tokio & Async I/O](https://sharpskill.dev/th/technologies/rust/interview-questions/tokio-async.md): 22 คำถาม, Senior - [การเพิ่มประสิทธิภาพ](https://sharpskill.dev/th/technologies/rust/interview-questions/performance-optimization.md): 20 คำถาม, Senior - [Memory Management](https://sharpskill.dev/th/technologies/rust/interview-questions/memory-management.md): 20 คำถาม, Senior - [Web Frameworks](https://sharpskill.dev/th/technologies/rust/interview-questions/web-frameworks.md): 22 คำถาม, Senior - [Database Integration](https://sharpskill.dev/th/technologies/rust/interview-questions/database-integration.md): 20 คำถาม, Senior - [Design Pattern ของ Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/design-patterns.md): 20 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/rust/interview-questions/unsafe-rust