Pass by value และ Pass by reference
ไม่ถูกต้องครับ Go และ C ไม่เคยมี pass by reference
ขอบคุณครับ เรื่องนี้ทำให้ผมเข้าใจผิดอยู่นาน เพราะสาเหตุที่เราส่ง pointer เข้าไปใน function นั้น มันดูเหมือนกับการ pass by reference แต่จริงๆแล้วมันคือ การ copy address ไว้ใน object ใหม่ ไม่ได้มีการส่ง object มาที่ function จริงๆ ที่ถูกควรเป็น pass by value ที่น่าตลกก็คือ สิ่งที่ทำให้ผมคิดว่าเป็น pass by reference อีกอย่างคือ ตัว pointer มันเป็น reference type ก็เลยคิดว่ามัน pass by reference
อันนี้ครับเว็บทางการ Go ก็บอกเอาไว้ golang.org/doc/faq#Pointers
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.
Pass by value และ Pass by reference
ไม่ถูกต้องครับ Go และ C ไม่เคยมี pass by reference
ขอบคุณครับ เรื่องนี้ทำให้ผมเข้าใจผิดอยู่นาน
เพราะสาเหตุที่เราส่ง pointer เข้าไปใน function นั้น มันดูเหมือนกับการ pass by reference แต่จริงๆแล้วมันคือ การ copy address ไว้ใน object ใหม่ ไม่ได้มีการส่ง object มาที่ function จริงๆ ที่ถูกควรเป็น pass by value
ที่น่าตลกก็คือ สิ่งที่ทำให้ผมคิดว่าเป็น pass by reference อีกอย่างคือ ตัว pointer มันเป็น reference type ก็เลยคิดว่ามัน pass by reference
อันนี้ครับเว็บทางการ Go ก็บอกเอาไว้
golang.org/doc/faq#Pointers