How to find the capacity of Channel, Pointer and Slice in Golang? Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Go language, capacity defines the maximum number of elements that a particular can hold. Here the task is to find the capacity of Channel, Pointer, and Slice in Golang, we can use the cap() function. Syntax: func cap(l Type) int Here, the type of l is a pointer. Let us discuss this concept with the help of the examples: Example 1: In this example, cap() function is used to find the capacity of Pointer in Golang. C // Go program to illustrate how to find the // capacity of the pointer package main import ( "fmt" ) // Main function func main() { // Creating and initializing // pointer // Using var keyword var ptr1 [7]*int var ptr2 [5]*string var ptr3 [8]*float64 // Finding the capacity of // the pointer // Using cap function fmt.Println("Capacity of ptr1: ", cap(ptr1)) fmt.Println("Capacity of ptr2: ", cap(ptr2)) fmt.Println("Capacity of ptr3: ", cap(ptr3)) } Output: Capacity of ptr1: 7 Capacity of ptr2: 5 Capacity of ptr3: 8 Example 2: In this example, cap() function is used to find the capacity of Channel in Golang. C // Go program to illustrate how to find the // capacity of the Channel package main import ( "fmt" ) // Main function func main() { // Creating and initializing // Channel // Using var keyword ch1 := make(chan int, 7) ch2 := make(chan string, 5) ch3 := make(chan float64, 8) // Finding the capacity of // the Channel // Using cap function fmt.Println("Capacity of Channel1: ", cap(ch1)) fmt.Println("Capacity of Channel2: ", cap(ch2)) fmt.Println("Capacity of Channel3: ", cap(ch3)) } Output: Capacity of Channel1: 7 Capacity of Channel2: 5 Capacity of Channel3: 8 Example 3: In this example, cap() function is used to find the capacity of Slice in Golang. C // Go program to illustrate how to find the // capacity of the Slice package main import ( "fmt" ) // Main function func main() { // Creating and initializing // Slice // Using var keyword sl1 := make([]int, 0, 7) sl2 := make([]string, 0, 5) sl3 := make([]float64, 0, 8) // Finding the capacity of // the Slice // Using cap function fmt.Println("Capacity of Slice1: ", cap(sl1)) fmt.Println("Capacity of Slice2: ", cap(sl2)) fmt.Println("Capacity of Slice3: ", cap(sl3)) } Output: Capacity of Slice1: 7 Capacity of Slice2: 5 Capacity of Slice3: 8 Comment More infoAdvertise with us Next Article How to find the length of the pointer in Golang? S shubhamsingh10 Follow Improve Article Tags : Go Language Golang-Pointers Golang-Slices Golang-Program Similar Reads How to find the capacity of the pointer in Golang? Pointers in Go programming language or Golang is a variable which is used to store the memory address of another variable. Pointers in Golang are also termed as the special variables. The variables are used to store some data at a particular memory address in the system. The memory address is always 2 min read How to find the Length of Channel, Pointer, Slice, String and Map in Golang? In Golang, len function is used to find the length of a channel, pointer, slice, string, and map. Channel: In Go language, a channel is a medium through which a goroutine communicates with another goroutine and this communication is lock-free. C // Go program to illustrate // how to find the length 2 min read How to find the length of the pointer in Golang? Pointers in Go programming language or Golang is a variable which is used to store the memory address of another variable. Pointers in Golang are also termed as the special variables. The variables are used to store some data at a particular memory address in the system. The memory address is always 2 min read How to Create and Print Multi Dimensional Slice in Golang? Slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. It is just like an array having an index value and length, but the size of the slice is resized they are not in fixed-size just like an array. Inter 2 min read How to split a slice of bytes after the given separator in Golang? In Go language slice is more powerful, flexible, convenient than an array, and is a lightweight data structure. The slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. In the Go slice of bytes, you ar 3 min read How to find the index value of any element in slice of bytes in Golang? In Go language slice is more powerful, flexible, convenient than an array, and is a lightweight data structure. The slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. In the Go slice of bytes, you ca 3 min read Like