声明:
package main
import "fmt"
func main() {
// 数组声明
s1 := make([]int,5)
fmt.Printf("The length of s1: %d\n", len(s1)) //5
fmt.Printf("The capacity of s1: %d\n", cap(s1)) //5
fmt.Printf("The value of s1: %d\n", s1) // [0 0 0 0 0]
s4 := [5]int{0,1,2}
fmt.Printf("The length of s4: %d\n", len(s4)) //5
fmt.Printf("The capacity of s4: %d\n", cap(s4)) //5
fmt.Printf("The value of s4: %d\n", s4) // [0 1 2 0 0]
// 切片声明
s2 := make([]int, 5, 8)
fmt.Printf("The length of s2: %d\n", len(s2)) //5
fmt.Printf("The capacity of s2: %d\n", cap(s2)) //8
fmt.Printf("The value of s2: %d\n", s2) // [0 0 0 0 0]
s3 := []int{0,1,2,3,4}
fmt.Printf("The length of s3: %d\n", len(s3)) //5
fmt.Printf("The capacity of s3: %d\n", cap(s3)) //5
fmt.Printf("The value of s3: %d\n", s3) // [0 1 2 3 4]
}
package main
import "fmt"
func m