August 2019
Beginner to intermediate
798 pages
17h 2m
English
In Chapter 3, Working with Basic Go Data Types, we talked about pointers. In this section, we will look at an example that is related to pointers to structures. The name of the program will be pointerStruct.go and will be presented in four parts.
The first part of the program contains the next Go code:
package main
import (
"fmt"
)
type myStructure struct {
Name string
Surname string
Height int32
}
The second code segment from pointerStruct.go follows:
func createStruct(n, s string, h int32) *myStructure {
if h > 300 {
h = 0
}
return &myStructure{n, s, h}
}
The approach used in createStruct() for creating a new structure variable has many advantages over initializing structure variables on your own, including the ...
Read now
Unlock full access