Skip to content

Commit

Permalink
Added little explanation about length and capacity of slices and two …
Browse files Browse the repository at this point in the history
…different ways of declaring them
  • Loading branch information
shivaji43 committed Jul 9, 2024
1 parent 388486e commit 138633e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arrays-and-slices.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func SumAll(numbersToSum ...[]int) []int {
Lots of new things to learn!

There's a new way to create a slice. `make` allows you to create a slice with
a starting capacity of the `len` of the `numbersToSum` we need to work through.
a starting capacity of the `len` of the `numbersToSum` we need to work through.The length of a slice is the number of elements it holds `len(mySlice)`, while the capacity is the number of elements it can hold in the underlying array `cap(mySlice)`, e.g., `make([]int, 0, 5)` creates a slice with length 0 and capacity 5.

You can index slices like arrays with `mySlice[N]` to get the value out or
assign it a new value with `=`
Expand Down

0 comments on commit 138633e

Please sign in to comment.