Skip to content

Instantly share code, notes, and snippets.

@toashd
Created December 29, 2015 14:53
Show Gist options
  • Save toashd/3416a19b23ba76217521 to your computer and use it in GitHub Desktop.
Save toashd/3416a19b23ba76217521 to your computer and use it in GitHub Desktop.
Golang array vs. slice
package main
import (
"fmt"
"reflect"
)
func main() {
var i = [...]uint8{0, 7, 16, 22, 28} // array, compiler counts elements
var j = []uint8{0, 7, 16, 22, 28} // slice
fmt.Println(len(i), cap(i), reflect.TypeOf(i), i)
fmt.Println(len(j), cap(j), reflect.TypeOf(j), j)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment