mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 06:19:44 +08:00
19 lines
430 B
Go
19 lines
430 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
//var slice1 []int = make([]int, 0, 10)
|
|
slice1 := make([]int, 0, 10)
|
|
// load the slice, cap(slice1) is 10:
|
|
for i := 0; i < cap(slice1); i++ {
|
|
slice1 = slice1[0:i+1] // reslice
|
|
slice1[i] = i
|
|
fmt.Printf("The length of slice is %d\n", len(slice1))
|
|
}
|
|
// print the slice:
|
|
for i := 0; i < len(slice1); i++ {
|
|
fmt.Printf("Slice at %d is %d\n", i, slice1[i])
|
|
}
|
|
}
|