Find capacity of Channel, Pointer and Slice
The builtin Cap function is used to find the capacity of Channel, Pointer and Slice. There is no package need to import to use Cap function.
Example
package main
import "fmt"
func main() {
sliceEx := make([]string, 0, 10)
fmt.Printf("\nSlice: %d", cap(sliceEx))
channelEx := make(chan string, 5)
fmt.Printf("\nChannel: %d", cap(channelEx))
var pointerEx *[20]string
fmt.Printf("\nPointer: %d", cap(pointerEx))
}
Output
Slice: 10
Channel: 5
Pointer: 20
Most Helpful This Week
Get Hours, Days, Minutes and Seconds difference between two dates [Future and Past]
How to get first and last element of slice in Golang?
How to convert Go struct to JSON?
Example of Sscan vs Sscanf vs Sscanln from FMT Package
Regular expression to extract numbers from a string in Golang
How to read/write from/to file in Golang?