go to create a slice

package main

import "fmt"

func main()  {
      // automatic derivation types, simultaneously initialized 
     S1: = [] int { . 1 , 2 , . 3 , . 4 }
     fmt.Println("s1=",s1)

     // means make way to create a slice (type length capabilities) 
     S2: = make ([] int , . 5 , 10 )
     fmt.Println(s2)
     fmt.Printf("len=%d,cap=%d\n",len(s2),cap(s2))

     // If you do not specify the same length and capacity capacity 
    S3: = the make ([] int , . 5 )
    fmt.Printf("len=%d,cap=%d\n",len(s3),cap(s3))

}

 

Guess you like

Origin www.cnblogs.com/dqh123/p/12076230.html