CodeFinity
CodeFinity

Reputation: 1340

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

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?

Upvotes: 0

Views: 187

Answers (1)

Paulo Mattos
Paulo Mattos

Reputation: 19339

Yes, a pointer to the first slice element in the backing array. I bet this wording comes from Go language C background :)

Upvotes: 1

Related Questions