func doubleAllElement(nums []int) { for i := range nums { nums[i] *= 2 } } func main() { nums := []int{1, 2, 3} doubleAllElement(nums) fmt.Println(nums) }
การส่ง arrays ก็เป็นการส่งค่าของ address ไปด้วยหรอครับ แล้วตอนมีการเปลี่ยนค่า ก็ไม่ต้องใช้ * เหมือน struct ใช่ไหมครับ
*
slice นะครับ ไม่ใช่ array ตัว slice เองเก็บ 3 อย่าง Len, cap, และ address ของ element
ขอบคุณมากครับ
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
การส่ง arrays ก็เป็นการส่งค่าของ address ไปด้วยหรอครับ แล้วตอนมีการเปลี่ยนค่า ก็ไม่ต้องใช้
*
เหมือน struct ใช่ไหมครับslice นะครับ ไม่ใช่ array ตัว slice เองเก็บ 3 อย่าง Len, cap, และ address ของ element
ขอบคุณมากครับ