如何在Golang中找到指针的长度？

``func len(l Type) int``

``````//Go program to illustrate how to find the
//length 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 [6]* int
var ptr2 [3]*string
var ptr3 [4]*float64

//Finding the length of
//the pointer to array
//Using len function
fmt.Println( "Length of ptr1: " , len(ptr1))
fmt.Println( "Length of ptr2: " , len(ptr2))
fmt.Println( "Length of ptr3: " , len(ptr3))

}``````

``````Length of ptr1:  6
Length of ptr2:  3
Length of ptr3:  4``````

``````//Go program to illustrate how to find
//the length of the pointer to an array
package main

import (
"fmt"
)

//Main function
func main() {

//Creating an array
arr := [6] int {200, 300, 400, 500, 600, 700}

var x int

//Creating pointer
var p [4]* int

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 length
//Using len() function
fmt.Println( "Length of arr: " , len(arr))
fmt.Println( "Length of p: " , len(p))
}``````

``````Value of p[0] = 200
Value of p[1] = 300
Value of p[2] = 400
Value of p[3] = 500
Length of arr:  6
Length of p:  4``````