

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Arrays in Go
incomplete
2: Slices in Go
incomplete
3: Slices Review
incomplete
4: Make
incomplete
5: Len and Cap Review
incomplete
6: Variadic
incomplete
7: Append
incomplete
8: Range
incomplete
9: Slice of Slices
incomplete
10: Tricky Slices
incomplete
11: Message Filter
incomplete
12: Password Strength
incomplete
13: Message Tagger
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Click to play video
Slices wrap arrays to give a more general, powerful, and convenient interface to sequences of data. Except for items with explicit dimensions such as transformation matrices, most array programming in Go is done with slices rather than simple arrays.
Slices hold references to an underlying array, and if you assign one slice to another, both refer to the same array. If a function takes a slice argument, any changes it makes to the elements of the slice will be visible to the caller, analogous to passing a pointer (we'll cover pointers later) to the underlying array. A Read function can therefore accept a slice argument rather than a pointer and a count; the length within the slice sets an upper limit of how much data to read. Here is the signature of the Read() method of the File type in package os:
Referenced from Effective Go
func (f *File) Read(buf []byte) (n int, err error)