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

王林
Release: 2024-02-06 09:20:03
forward
506 people have browsed it

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template