Menu Close

Go – How to find the length of the pointer array in go

In this tutorial, We are going to learn about how to find the length of the pointer array in go. We can do it by using len() built-in function in go.

In go, A pointer is a variable which is used to store the address of another variable.

Function prototype:

func len(v Type) int

Return type:

len() built-in function returns 
the length of map, slice, arrays and channel.

Example with code:

package main

import (



func main() {

  var p1 [5] *int

  var p2 [3] *string

  var p3 [4] *float32

  fmt.Println("Length of p1: ", len(p1))

  fmt.Println("Length of p1: ", len(p2))

  fmt.Println("Length of p1: ", len(p3))



Length of p1: 5

Length of p1: 3

Length of p1: 4

To learn more about golang, You can refer given below link:

Posted in builtin, golang

Leave a Reply

Your email address will not be published. Required fields are marked *