Created
December 29, 2015 14:53
-
-
Save toashd/3416a19b23ba76217521 to your computer and use it in GitHub Desktop.
Golang array vs. slice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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