Accessing struct fields
📖 Scenario: You are creating a simple program to store information about a book in a library.
🎯 Goal: You will create a struct to hold book details, set up a book variable, and then access and print its fields.
📋 What You'll Learn
Create a struct type named
Book with fields Title (string) and Pages (int).Create a variable
myBook of type Book with Title set to "Go Programming" and Pages set to 300.Access the
Title and Pages fields of myBook and store them in variables bookTitle and bookPages.Print the values of
bookTitle and bookPages.💡 Why This Matters
🌍 Real World
Structs are used to group related data together, like storing information about books, people, or products in programs.
💼 Career
Understanding structs and how to access their fields is essential for Go programming jobs, especially when working with data models and APIs.
Progress0 / 4 steps