Built-in function

Go make()

Initializes a slice, map or channel and returns a value of that type, not a pointer. Slice length is required; capacity defaults to length. Map size is an optional allocation hint; channel buffer size defaults to zero. Invalid runtime slice sizes can panic. Example prints 2 4.

Formal Syntax & Structure

go syntaxgo
make(sliceType, length [, capacity]) | make(mapType [, hint]) | make(channelType [, bufferSize])

Parameters & Attributes

NameTypeDescription
Tslice, map or channel typeContainer type.
sizeintegerRequired slice length; optional map hint or channel buffer size.
capacityintegerOptional slice capacity, at least the length.

Return Value

T

Initialized container value.

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  s := make([]int, 2, 4)  fmt.Println(len(s), cap(s))}
Go Reference