Home >Backend Development >Golang >func (*TCPConn) reads the updated byte value, even if the argument is not a pointer
My understanding of Golang method/function parameters is that it works by call by value
. But I came across this method call func (c *TCPConn) Read(b []byte) (int, error)
where the parameter is a non-pointer but it updates the variable value in the caller. I think I'm missing something. Please help to understand this case.
This depends on the type of the parameter. []byte
is a slice, and a slice is actually like a pointer. Maps are pointers too, so consider this when using slices and maps in functions.
https://www.php.cn/link/5d9e4a04afb9f3608ccc76c1ffa7573e:
The above is the detailed content of func (*TCPConn) reads the updated byte value, even if the argument is not a pointer. For more information, please follow other related articles on the PHP Chinese website!