Go有什么指针? [英] What's the point of having pointers in Go?

查看:79
本文介绍了Go有什么指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Go中的指针允许函数参数的变异,但如果它们只采用引用(使用适当的const或可变限定符)并不会更简单。现在我们有指针和一些内置类型,比如地图和频道隐式通过引用。

I know that pointers in Go allow mutation of a function's arguments, but wouldn't it have been simpler if they adopted just references (with appropriate const or mutable qualifiers). Now we have pointers and for some built-in types like maps and channels implicit pass by reference.

我在Go中丢失了什么或者是指针,只是一个不必要的并发症? / p>

Am I missing something or are pointers in Go just an unnecessary complication?

推荐答案

引用不能被重新分配,而指针可以。仅在这种情况下,这些指针在许多不能使用引用的情况下都很有用。

References cannot be reassigned, while pointers can. This alone makes pointers useful in many situations where references could not be used.

这篇关于Go有什么指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆