A Go slice holds a reference to a subsection of an array or just a single element?

huangapple go评论147阅读模式
英文:

A Go slice holds a reference to a subsection of an array or just a single element?

问题

Golang关于切片和数组的博客

将切片视为一个小的数据结构,它有两个元素:长度和指向数组元素的指针。

对于说“...指向数组元素的指针”的措辞感到有些困惑。只有当切片的len()为1时,才会是这种情况,对吗?

我认为博客文章可能是想说它是指向数组的“子部分”的指针,对吗?

英文:

Golang blog about slices and arrays

> think of a slice as a little data structure with two elements: a length and a pointer to an element of an array.

Little bewildered by verbiage saying: '...pointer to an ELEMENT of an array.' That would only be the case if it was a slice with len() of 1, right?

I believe the blog post may have meant to say that it was a pointer to a 'subsection' of an array, right?

答案1

得分: 1

是的,这是指向底层数组中第一个切片元素的指针。我敢打赌这个措辞来自Go语言的C背景 A Go slice holds a reference to a subsection of an array or just a single element?

英文:

Yes, a pointer to the first slice element in the backing array. I bet this wording comes from Go language C background A Go slice holds a reference to a subsection of an array or just a single element?

huangapple
  • 本文由 发表于 2017年5月20日 07:42:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/44080412.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定