Go TutorialLesson 17Free preview
Go Struct
This lesson is part of Go · All levels
Summary
This lesson introduces struct, the way Go combines multiple fields of different types into one dataset type called. The struct value is accessed via the (.), and the struct is of a value type so that the assignment copies the entire contents. To modify the struct without copying, use the pointer to the struct with the & mark.
Key points
- Struct is declared with type Name struct {field type;...}
- Fields are accessed using dots, e.g. orang.Nama
- Struct is of value type so the assignment produces a copy
- Pointer to struct (&) is used to make the modification visible on the original data
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.