# โครงสร้างข้อมูล Go (Go) > Arrays, slices, maps, structs, pointers, make vs new, ค่า nil - 20 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: Go](https://sharpskill.dev/th/technologies/go/interview-questions.md) ## 1. slice ใน Go คืออะไร? **คำตอบ** slice คือมุมมองแบบไดนามิกบน array ที่อยู่เบื้องหลัง ซึ่งช่วยให้จัดการลำดับของสมาชิกที่มีความยาวแปรผันได้ ต่างจาก array ที่มีขนาดคงที่กำหนดตั้งแต่ตอนคอมไพล์ slice สามารถขยายหรือหดได้แบบไดนามิกผ่านการดำเนินการอย่าง append ความยืดหยุ่นนี้ทำให้มันเป็นโครงสร้างข้อมูลแบบลำดับที่ใช้บ่อยที่สุดใน Go สำหรับเก็บคอลเลกชันของสมาชิกชนิดเดียวกัน ## 2. ความแตกต่างหลักระหว่าง array กับ slice ใน Go คืออะไร? **คำตอบ** ความแตกต่างพื้นฐานอยู่ที่ขนาด: array มีขนาดคงที่ที่กำหนดตอนคอมไพล์และเป็นส่วนหนึ่งของชนิดข้อมูลเอง ในขณะที่ slice มีขนาดแบบไดนามิกที่เปลี่ยนแปลงได้ตอนรันไทม์ ความแตกต่างนี้หมายความว่า array สองตัวที่มีขนาดต่างกันถือเป็นชนิดที่เข้ากันไม่ได้ ในขณะที่ slice ทุกตัวที่มีชนิดสมาชิกเดียวกันเข้ากันได้ ดังนั้น slice จึงยืดหยุ่นกว่าและถูกใช้บ่อยกว่าในโค้ด Go สมัยใหม่ ## 3. จะสร้าง slice ว่างใน Go ได้อย่างไร? **คำตอบ** ไวยากรณ์ literal ที่ใช้วงเล็บเหลี่ยมว่างตามด้วยวงเล็บปีกกาว่างเป็นวิธีที่เป็นสำนวนในการสร้าง slice ว่างที่ถูกกำหนดค่าเริ่มต้นแล้ว วิธีนี้สร้าง slice ที่มีความยาว 0 แต่ไม่เป็น nil พร้อมรับสมาชิกผ่าน append ต่างจากการประกาศแบบธรรมดาที่จะได้ slice แบบ nil การกำหนดค่าเริ่มต้นอย่างชัดเจนนี้รับประกัน slice ที่ใช้งานได้ทันทีโดยไม่มีความเสี่ยงของพฤติกรรมที่ไม่คาดคิดเมื่อเพิ่มสมาชิก ## มีอีก 17 คำถาม - ควรใช้ฟังก์ชันใดเพื่อกำหนดค่าเริ่มต้น slice ด้วยความจุที่ระบุ? - เกิดอะไรขึ้นเมื่อเพิ่มสมาชิกลงใน slice ที่ความจุเต็มแล้ว? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Go อื่นๆ - [พื้นฐาน Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-basics.md): 25 คำถาม, Junior - [อินเทอร์เฟซใน Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-interfaces.md): 18 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/go/interview-questions/error-handling.md): 20 คำถาม, Junior - [พื้นฐาน Goroutine](https://sharpskill.dev/th/technologies/go/interview-questions/goroutines-basics.md): 20 คำถาม, Junior - [Channels](https://sharpskill.dev/th/technologies/go/interview-questions/channels.md): 22 คำถาม, Junior - [Go Modules](https://sharpskill.dev/th/technologies/go/interview-questions/go-modules.md): 18 คำถาม, Mid-Level - [เซิร์ฟเวอร์ HTTP](https://sharpskill.dev/th/technologies/go/interview-questions/http-server.md): 24 คำถาม, Mid-Level - [ไคลเอนต์ HTTP](https://sharpskill.dev/th/technologies/go/interview-questions/http-client.md): 18 คำถาม, Mid-Level - [การเข้ารหัส JSON](https://sharpskill.dev/th/technologies/go/interview-questions/json-encoding.md): 20 คำถาม, Mid-Level - [Database/SQL](https://sharpskill.dev/th/technologies/go/interview-questions/database-sql.md): 22 คำถาม, Mid-Level - [แพ็กเกจ context](https://sharpskill.dev/th/technologies/go/interview-questions/context-package.md): 20 คำถาม, Mid-Level - [Testing](https://sharpskill.dev/th/technologies/go/interview-questions/testing.md): 22 คำถาม, Mid-Level - [รูปแบบ Concurrency](https://sharpskill.dev/th/technologies/go/interview-questions/concurrency-patterns.md): 24 คำถาม, Mid-Level - [ไพรมิทีฟการซิงโครไนซ์](https://sharpskill.dev/th/technologies/go/interview-questions/sync-primitives.md): 22 คำถาม, Mid-Level - [เฟรมเวิร์กเว็บ Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-web-frameworks.md): 20 คำถาม, Mid-Level - [การออกแบบ REST API](https://sharpskill.dev/th/technologies/go/interview-questions/rest-api-design.md): 20 คำถาม, Mid-Level - [gRPC](https://sharpskill.dev/th/technologies/go/interview-questions/grpc.md): 22 คำถาม, Mid-Level - [Reflection](https://sharpskill.dev/th/technologies/go/interview-questions/reflection.md): 20 คำถาม, Senior - [การจัดการหน่วยความจำ](https://sharpskill.dev/th/technologies/go/interview-questions/memory-management.md): 24 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/go/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [Generics](https://sharpskill.dev/th/technologies/go/interview-questions/generics.md): 20 คำถาม, Senior - [Go Design Patterns](https://sharpskill.dev/th/technologies/go/interview-questions/design-patterns.md): 24 คำถาม, Senior - [Microservices](https://sharpskill.dev/th/technologies/go/interview-questions/microservices.md): 24 คำถาม, Senior - [ความปลอดภัยและการยืนยันตัวตน](https://sharpskill.dev/th/technologies/go/interview-questions/security-authentication.md): 24 คำถาม, Senior - [Docker & Containerization](https://sharpskill.dev/th/technologies/go/interview-questions/docker-containerization.md): 20 คำถาม, Senior - [Kubernetes Basics](https://sharpskill.dev/th/technologies/go/interview-questions/kubernetes-basics.md): 22 คำถาม, Senior - [Go ขั้นสูง](https://sharpskill.dev/th/technologies/go/interview-questions/advanced-go.md): 20 คำถาม, Senior - [การพัฒนา CLI](https://sharpskill.dev/th/technologies/go/interview-questions/cli-development.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/go/interview-questions/go-data-structures