Nested structs
📖 Scenario: You are creating a simple program to store information about a book and its author. The author has a name and an age. The book has a title and an author.
🎯 Goal: You will build a Go program that uses nested structs to represent a book and its author, then print the book's title and the author's name.
📋 What You'll Learn
Create a struct called
Author with fields Name string and Age int.Create a struct called
Book with fields Title string and Author Author.Create a variable
myBook of type Book with title "Go Programming" and author name "Alice" aged 30.Print the book's title and the author's name exactly as shown.
💡 Why This Matters
🌍 Real World
Nested structs are useful to model real-world objects that have parts or details inside them, like a book having an author.
💼 Career
Understanding nested structs is important for Go developers working on data modeling, APIs, and complex data structures.
Progress0 / 4 steps