2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-15 06:12:59 +00:00
cheat.sheets/sheets/_go/Arrays
2017-05-28 21:17:32 +00:00

13 lines
415 B
Plaintext

// gives you the length of an array/a slice
// It's a built-in function, not a attribute/method on the array.
len(a)
var a [10]int // declare an int array with length 10. Array length is part of the type!
a[3] = 42 // set elements
i := a[3] // read elements
// declare and initialize
var a = [2]int{1, 2}
a := [2]int{1, 2} //shorthand
a := [...]int{1, 2} // elipsis -> Compiler figures out array length