reflect.Indirect() Function in Golang with Examples Last Updated : 28 Apr, 2020 Comments Improve Suggest changes Like Article Like Report Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Indirect() Function in Golang is used to get the value that v points to, i.e., If v is a nil pointer, Indirect returns a zero Value. If v is not a pointer, Indirect returns v. To access this function, one needs to imports the reflect package in the program. Syntax: func Indirect(v Value) Value Parameters: This function takes the following parameters: v: This parameter is the value to be passed. Return Value: This function returns the value that v points to. Below examples illustrate the use of the above method in Golang: Example 1: C // Golang program to illustrate // reflect.Indirect() Function package main import ( "fmt" "reflect" ) // Main function func main() { val1:= []int {1, 2, 3, 4} var val2 reflect.Value = reflect.ValueOf(&val1) fmt.Println("&val2 type : ", val2.Kind()) // using the function indirectI := reflect.Indirect(val2) fmt.Println("indirectI type : ", indirectI.Kind()) fmt.Println("indirectI value : ", indirectI) } Output: &val2 type : ptr indirectI type : slice indirectI value : [1 2 3 4] Example 2: C // Golang program to illustrate // reflect.Indirect() Function package main import ( "fmt" "reflect" ) // Main function func main() { var val1 []int var val2 [3]string var val3 = make(map[int]string) var val4 reflect.Value = reflect.ValueOf(&val1) indirectI := reflect.Indirect(val4) fmt.Println("val1: ", indirectI.Kind()) var val5 reflect.Value = reflect.ValueOf(&val2) indirectStr := reflect.Indirect(val5) fmt.Println("val2 type : ", indirectStr.Kind()) var val6 reflect.Value = reflect.ValueOf(&val3) fmt.Println("&val3 type : ", val6.Kind()) indirectM := reflect.Indirect(val6) fmt.Println("val3 type : ", indirectM.Kind()) } Output: val1: slice val2 type : array &val3 type : ptr val3 type : map Comment More infoAdvertise with us Next Article reflect.Indirect() Function in Golang with Examples S SHUBHAMSINGH10 Follow Improve Article Tags : Go Language Golang-reflect Similar Reads reflect.Index() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Index() Function in Golang is used to get the v's i'th element. To access this function, one needs to imports the 2 min read reflect.Int() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Int() Function in Golang is used to get the v's underlying value, as an int64. To access this function, one needs 1 min read reflect.Kind() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Kind() Function in Golang is used to find the name of kind. To access this function, one needs to imports the ref 2 min read reflect.NewAt() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.NewAt() Function in Golang is used to get the Value representing a pointer to a value of the specified type, usin 2 min read reflect.IsNil() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.IsNil() Function in Golang is used to check whether its argument v is nil. The argument must be a chan, func, int 2 min read reflect.MapIndex() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.MapIndex() Function in Golang is used to get the value associated with key in the map v. To access this function, 2 min read reflect.New() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package.The reflect.New() Function in Golang is used to get the Value representing a pointer to a new zero value for the specified typ 2 min read reflect.Interface() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Interface() Function in Golang is used to get the v's current value as an interface{}. To access this function, o 2 min read reflect.Pointer() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Pointer() Function in Golang is used to get the v's value as a uintptr. To access this function, one needs to imp 2 min read reflect.PtrTo() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.PtrTo() Function in Golang is used to get the pointer type with element t, i.e., t represents type Geek, PtrTo(t) 1 min read Like