Skip to content

Instantly share code, notes, and snippets.

@bouzuya
Created November 7, 2015 03:21
Show Gist options
  • Select an option

  • Save bouzuya/52bb565af01324bb9438 to your computer and use it in GitHub Desktop.

Select an option

Save bouzuya/52bb565af01324bb9438 to your computer and use it in GitHub Desktop.
Array and Slice
package main
import "fmt"
func f(a [6]int) {
a[0] = 100
}
func g(s []int) {
s[0] = 100
}
func main() {
// array
a := [...]int{2, 3, 5, 7, 11, 13}
f(a)
fmt.Println("a ==", a) // a == [2 3 5 7 11 13]
// slice
s := []int{2, 3, 5, 7, 11, 13}
g(s)
fmt.Println("s ==", s) // s == [100 3 5 7 11 13]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment