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
Golang String Concatenation
How to check UPPERCASE characters in a string in Golang?
How to append text to a file in Golang?
Regular expression to extract DNS host-name or IP Address from string
How to iterate over an Array using for loop?
Example to handle GET and POST request in Golang
Subtract N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time.
How to delete or remove element from a Map?
How to read names of all files and folders in current directory?
How to Decode or Unmarshal bi-dimensional array of integers?