From 3da7b7dbc7156269f1493e73134f4ca969b22b9a Mon Sep 17 00:00:00 2001 From: Daniel Tomlinson Date: Sat, 3 Dec 2022 18:45:01 +0000 Subject: [PATCH] 2022-12-03 --- chapter-3-composite-types/01_arrays.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/chapter-3-composite-types/01_arrays.go b/chapter-3-composite-types/01_arrays.go index 06ab7d0..51406f6 100644 --- a/chapter-3-composite-types/01_arrays.go +++ b/chapter-3-composite-types/01_arrays.go @@ -1 +1,20 @@ +// array literals are their own types +// [3]int is a different type to [4]int + 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} +}