package main import ( "fmt" "reflect" ) func main() { v := 42 rv := reflect.ValueOf(v) fmt.Println("Type:", rv.Type()) // prints "Type: int" }
package main import ( "fmt" "reflect" ) func main() { v := 42 rv := reflect.ValueOf(&v).Elem() fmt.Println("Before:", v) // prints "Before: 42" rv.SetInt(84) fmt.Println("After:", v) // prints "After: 84" }In this example, we first create a value `v` of type `int`. We then create a `reflect.Value` `rv` using `reflect.ValueOf(&v).Elem()`, which gets the `reflect.Value` of the address of `v` and then dereferences it. Finally, we call the `SetInt` method of `rv` to set its value to `84`. We then print out the value of `v` before and after the set, which shows that the set was successful. Package library: `reflect`