How to find the capacity of the pointer in Golang? Last Updated : 05 Sep, 2019 Comments Improve Suggest changes Like Article Like Report 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 found in hexadecimal format(starting with 0x like 0xFFAAF etc.). In pointers, you are allowed to find the capacity of the pointer with the help of cap() function. This function is a built-in function returns the capacity of the pointer to array. In Go language, capacity defines the maximum number of elements stored in a pointer to array. This function is defined under builtin. 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: C // Go program to illustrate how to find the // capacity of the pointer to an array package main import ( "fmt" ) // Main function func main() { // Creating and initializing // pointer to array // Using var keyword var ptr1 [7]*int var ptr2 [5]*string var ptr3 [8]*float64 // Finding the capacity of // the pointer to array // 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: C // Go program to illustrate how to find the // capacity of the pointer to an array package main import ( "fmt" ) // Main function func main() { // Creating an array arr := [8]int{200, 300, 400, 500, 600, 700, 100, 200} var x int // Creating pointer var p [5]*int // Assigning the address for x = 0; x < len(p); x++ { p[x] = &arr[x] } // Displaying result for x = 0; x < len(p); x++ { fmt.Printf("Value of p[%d] = %d\n", x, *p[x]) } // Finding capacity // using cap() function fmt.Println("Capacity of arr: ", cap(arr)) fmt.Println("Capacity of p: ", cap(p)) } Output: Value of p[0] = 200 Value of p[1] = 300 Value of p[2] = 400 Value of p[3] = 500 Value of p[4] = 600 Capacity of arr: 8 Capacity of p: 5 Comment More infoAdvertise with us Next Article How to find the capacity of the pointer in Golang? A ankita_saini Follow Improve Article Tags : Go Language Golang-Pointers Golang 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 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 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 Pointer to a Struct in Golang In Go, structs are used to create custom data types that group different fields together. When working with structs, using pointers can be especially beneficial for managing memory efficiently and for avoiding unnecessary copying of data. A pointer to a struct allows you to directly reference and mo 3 min read Like