Skip to content

Instantly share code, notes, and snippets.

View jjuliano's full-sized avatar

Joel Bryan Juliano jjuliano

View GitHub Profile
const MAX_ARRAY_SIZE = 2
array := make([]string, MAX_ARRAY_SIZE)
array[0] = "foo"
array[1] = "bar"
fmt.Println(array[0])
fmt.Println(array[1])
fmt.Println(array)
// foo
array := make([]string, 2)
array := make([]string, 2, 3)
array[0] = "foo"
array[1] = "bar"
array[2] = "baz"
// oops, error
// array[2] = "baz"
// error
make(type, length, capacity)
array := make([]string, 2, 3)
array[0] = "foo"
array[1] = "bar"
array := make([]string, 2, 2)
array2 := array[:3]
// so this would results to an error
// array2[3] = "foobar"