type Person struct { Name string Age int } func main() { p := &Person{"John Doe", 30} pType := reflect.TypeOf(p) elemType := pType.Elem() fmt.Println(elemType) }
type Book struct { Title string Author string } func main() { b := &Book{"The Catcher in the Rye", "J.D. Salinger"} bType := reflect.TypeOf(b) elemType := bType.Elem() fmt.Println(elemType) }This code defines a struct `Book` and creates a new instance of it. It then retrieves its type using `reflect.TypeOf()` and gets the element type using `Elem()`. The output will be `main.Book`. Package: `reflect`