How to find the Length of Channel, Pointer, Slice, String and Map in Golang? Last Updated : 10 May, 2020 Comments Improve Suggest changes Like Article Like Report 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 a channel package main import "fmt" func main() { // Creating a channel using make() function ch:= make(chan int, 5) fmt.Printf("\nChannel: %d", len(ch)) ch <- 0 ch <- 1 ch <- 2 fmt.Printf("\nChannel: %d", len(ch)) } Output: Channel: 0 Channel: 3 Pointer: Pointers in Go programming language or Golang is a variable which is used to store the memory address of another variable. C // Go program to illustrate // how to find the length a Pointer. package main import "fmt" func main() { // Creating a pointer var poin *[10]string fmt.Printf("\nPointer: %d", len(poin)) } Output: Pointer: 10 Slice: 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. C // Go program to illustrate // how to find length Slice package main import "fmt" func main() { // Creating a slice using make() function sliceEx := make([]int, 10) fmt.Printf("\nSlice: %d", len(sliceEx)) } Output: Slice: 10 String: It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding. C // Go program to illustrate // how to find length a String. package main import "fmt" func main() { // Creating a string strEx := "India" fmt.Printf("\nString: %d", len(strEx)) } Output: String: 5 Map: Golang Maps is a collection of unordered pairs of key-value. C // Go program to illustrate // how to find length a Map. package main import "fmt" func main() { // Creating a map using make() function mapEx := make(map[string]int) mapEx["A"] = 10 mapEx["B"] = 20 mapEx["C"] = 30 fmt.Printf("\nMap: %d", len(mapEx)) } Output: Map: 3 Comment More infoAdvertise with us Next Article How to find the Length of Channel, Pointer, Slice, String and Map in Golang? N NikhilChandwani Follow Improve Article Tags : Go Language Golang-Program Similar Reads How to find the capacity of Channel, Pointer and Slice in Golang? 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 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 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 Compare Equality of Struct, Slice and Map in Golang? In Golang, reflect.DeepEqual function is used to compare the equality of struct, slice, and map in Golang. It is used to check if two elements are "deeply equal" or not. Deep means that we are comparing the contents of the objects recursively. Two distinct types of values are never deeply equal. Two 3 min read How to copy one slice into another slice in Golang? In Go, a Slice is a variable-length sequence that can hold elements of the same type. You canât mix different types of elements in a single slice. To copy one slice into another, Go provides a built-in function called copy(). This function allows you to duplicate the elements from one slice (the sou 3 min read How to Find Length of Struct in Golang? In programming, data structures are vital in organizing and storing data efficiently. One such data structure in Go, also known as Golang, is the struct. This article will delve into the concept of structure in Golang and explore various methods to find its length.Table of ContentWhat is Struct with 5 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 Searching an element of string type in Golang slice 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, you can search 3 min read Program to find the Length of the longest substring without repeating characters in Golang Given a string, print the longest substring without repeating characters in Golang. For example, the longest substrings without repeating characters for âABDEFGABEFâ are âBDEFGAâ. Examples: Input : GEEKSFORGEEKS Output : Substring: EKSFORG Length: 7 Input : ABDEFGABEF Output : Substring: BDEFGA Leng 4 min read How to Get First and Last Element of Slice in Golang? Go language slice is more powerful, flexible, convenient than an array, and is a lightweight data structure. 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 inde 2 min read Like