Slices in Go
This is a study note from YouTube Go tutorial https://www.youtube.com/watch?v=YS4e4q9oBaU Slice is used in most of cases in Go instead of arrays because it is dynamic. This means you can increase the capacity of slice on the runtime. You can create a slice like below: Slice creation using []int a := [] int { 1 , 2 , 3 } It is very similar to array creation except no size in the square bracket "[]". Unlike array is a value type, slice is a reference type like list in Java. So when you create a slice and then assign it to another slice variable, both of them refer to the same memory. package main import ( "fmt" ) func main () { a := [] int { 1 , 2 , 3 } b := a b[ 1 ] = 5 fmt. Println (a) fmt. Println (b) fmt. Printf ( "Length: %v \n " , len (a)) fmt. Printf ( "Capacity: %v \n " , cap (a)) } Result: [1 5 3] [1 5 3] Length: 3 Capacity: 3 From the result, you can see both a and b has the same values even thou...