1.

How To Define A Slice In Go?

Answer»

To DEFINE a slice, you can DECLARE it as an array without specifying SIZE or use make function to CREATE the one.

var numbers []int /* a slice of unspecified size */
/* numbers == []int{0,0,0,0,0}*/
numbers = make([]int,5,5) /* a slice of LENGTH 5 and capacity 5*/

To define a slice, you can declare it as an array without specifying size or use make function to create the one.

var numbers []int /* a slice of unspecified size */
/* numbers == []int{0,0,0,0,0}*/
numbers = make([]int,5,5) /* a slice of length 5 and capacity 5*/



Discussion

No Comment Found