Home >Backend Development >Golang >func (*TCPConn) reads the updated byte value, even if the argument is not a pointer

func (*TCPConn) reads the updated byte value, even if the argument is not a pointer

王林
王林forward
2024-02-06 09:20:03466browse

func (*TCPConn) 读取更新字节值,即使参数不是指针

Question content

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.


Correct answer


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!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete