2022-12-03
This commit is contained in:
@@ -1 +1,20 @@
|
|||||||
|
// array literals are their own types
|
||||||
|
// [3]int is a different type to [4]int
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var x [3]int
|
||||||
|
|
||||||
|
x = [3]int{1, 2, 3}
|
||||||
|
fmt.Println(x)
|
||||||
|
|
||||||
|
// index 0=1, index 5=4, index 6=6, index 10=100, index 11=15, the rest 0
|
||||||
|
var y = [12]int{1, 5: 4, 6, 10: 100, 15}
|
||||||
|
fmt.Println(y)
|
||||||
|
|
||||||
|
// can leave the size off if initialising an array
|
||||||
|
var z = [...]int{1, 2, 3}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user