reflect.Pointer() Function in Golang with Examples Last Updated : 05 May, 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.Pointer() Function in Golang is used to get the v's value as a uintptr. To access this function, one needs to imports the reflect package in the program. Syntax: func (v Value) Pointer() uintptr Parameters: This function does not accept any parameter. Return Value: This function returns the v's value as a uintptr. Below examples illustrate the use of the above method in Golang: Example 1: C // Golang program to illustrate // reflect.Pointer() Function package main import ( "reflect" "unsafe" "fmt" ) func main() { var s = struct{ foo int }{100} var i int rs := reflect.ValueOf(&s).Elem() rf := rs.Field(0) ri := reflect.ValueOf(&i).Elem() // use of Pointer() method rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem() ri.Set(rf) rf.Set(ri) fmt.Println(rf) } Output: 100 Example 2: C // Golang program to illustrate // reflect.Pointer() Function package main import ( "fmt" "play.ground/foo" "reflect" "unsafe" ) func GetUnexportedField(field reflect.Value) interface{} { return reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface() } func SetUnexportedField(field reflect.Value, value interface{}) { reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())). Elem(). Set(reflect.ValueOf(value)) } func main() { f := &foo.Foo{ Exported: "Old Value ", } fmt.Println(f.Exported) field := reflect.ValueOf(f).Elem().FieldByName("unexported") SetUnexportedField(field, "New Value") fmt.Println(GetUnexportedField(field)) } -- go.mod -- module play.ground -- foo/foo.go -- package foo type Foo struct { Exported string unexported string } Output: Old Value New Value Comment More infoAdvertise with us Next Article reflect.Pointer() Function in Golang with Examples S SHUBHAMSINGH10 Follow Improve Article Tags : Go Language Golang-reflect Similar Reads 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.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 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.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.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.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.IsZero() 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.IsZero() Function in Golang is used to check whether v is the zero value for its type. To access this function, o 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.Indirect() 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.Indirect() Function in Golang is used to get the value that v points to, i.e., If v is a nil pointer, Indirect re 2 min read Like