Key Concepts

Review core concepts you need to learn to master this subject

Structs and Fields

In Go, a group of related variables can be defined as a struct. Each variable within a struct is known as a field.

Structs in Go
Lesson 1 of 1
  1. 1
    We often have many variables related to each other, but managing using them all together can be a headache. Luckily, Go provides us with a way to group several variables into one custom data type. …
  2. 2
    We’ve just learned the importance of structs in grouping complex data types. But how do we define the structs we’ll use in our programs? In this exercise, we will introduce the syntax for defining …
  3. 3
    We’ve defined our structs, but how do we create variables of that type? To use a struct we just defined, we have to create an instance of it. Assume we defined Point from the last exercise. We coul…
  4. 4
    We’ve defined our struct and created an instance, it’s time to use them. In this exercise, we will explore how to access and modify a struct’s variables. Let’s say we have an instance of the Stud…
  5. 5
    We can use functions to capture logic involving our structs and simplify it. Structs will often have important operations that can be performed on them. For example, with a struct representing a …
  6. 6
    Without pointers, when a variable is passed into a function, only a copy of it is used inside the function. We can use pointers to modify values in our structs within a function. But how do we get …
  7. 7
    What can we do when dealing with many structs of the same type? We can use them in an array together! Let’s say we want to create an array of the following points: {1, 1} {7, 27} {12, 7} {9, 25} W…
  8. 8
    When we have complex groups of fields in our structs, they can be combined into their own struct! For example, in the Employee struct, we have two separate fields for the first and last name of the…
  9. 9
    Good job on completing the module on struct in Go! You now have a strong understanding of how to create and use structs. Let’s review everything we went over. A group of related variables can be d…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo