## 4.1. 數組

var a [3]int             // array of 3 integers
fmt.Println(a[0])        // print the first element
fmt.Println(a[len(a)-1]) // print the last element, a[2]

// Print the indices and elements.
for i, v := range a {
fmt.Printf("%d %d\n", i, v)
}

// Print the elements only.
for _, v := range a {
fmt.Printf("%d\n", v)
}

var q [3]int = [3]int{1, 2, 3}
var r [3]int = [3]int{1, 2}
fmt.Println(r[2]) // "0"

q := [...]int{1, 2, 3}
fmt.Printf("%T\n", q) // "[3]int"

q := [3]int{1, 2, 3}
q = [4]int{1, 2, 3, 4} // compile error: cannot assign [4]int to [3]int

type Currency int

const (
USD Currency = iota // 美元
EUR                 // 歐元
GBP                 // 英鎊
RMB                 // 人民幣
)

symbol := [...]string{USD: "\$", EUR: "€", GBP: "￡", RMB: "￥"}

fmt.Println(RMB, symbol[RMB]) // "3 ￥"

r := [...]int{99: -1}

a := [2]int{1, 2}
b := [...]int{1, 2}
c := [2]int{1, 3}
fmt.Println(a == b, a == c, b == c) // "true false false"
d := [3]int{1, 2}
fmt.Println(a == d) // compile error: cannot compare [2]int == [3]int

gopl.io/ch4/sha256

import "crypto/sha256"

func main() {
c1 := sha256.Sum256([]byte("x"))
c2 := sha256.Sum256([]byte("X"))
fmt.Printf("%x\n%x\n%t\n%T\n", c1, c2, c1 == c2, c1)
// Output:
// 2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881
// false
// [32]uint8
}

func zero(ptr *[32]byte) {
for i := range ptr {
ptr[i] = 0
}
}

func zero(ptr *[32]byte) {
*ptr = [32]byte{}
}