Skip to content

Instantly share code, notes, and snippets.

@kjk
Created November 5, 2019 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjk/6d9409619a714a5077a2ce46b83b8b4d to your computer and use it in GitHub Desktop.
Save kjk/6d9409619a714a5077a2ce46b83b8b4d to your computer and use it in GitHub Desktop.
Arrays
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
a := [2]int{4, 5} // array of 2 ints
// access element of array
fmt.Printf("a[1]: %d\n", a[1])
// set element of array
a[1] = 3
// get size of array
fmt.Printf("size of array a: %d\n", len(a))
// when using [...] size will be deduced from { ... }
a2 := [...]int{4, 8, -1} // array of 3 integers
fmt.Printf("size of array a2: %d\n", len(a2))
// :show end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment