mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 04:48:29 +08:00
modify 07.1.md
This commit is contained in:
17
eBook/examples/chapter_7/make_slice.go
Normal file
17
eBook/examples/chapter_7/make_slice.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var slice1 []int = make([]int, 10)
|
||||
// load the array/slice:
|
||||
for i := 0; i < len(slice1); i++ {
|
||||
slice1[i] = 5 * i
|
||||
}
|
||||
|
||||
// print the slice:
|
||||
for i := 0; i < len(slice1); i++ {
|
||||
fmt.Printf("Slice at %d is %d\n", i, slice1[i])
|
||||
}
|
||||
fmt.Printf("\nThe length of slice1 is %d\n", len(slice1))
|
||||
fmt.Printf("The capacity of slice1 is %d\n", cap(slice1))
|
||||
}
|
Reference in New Issue
Block a user